Nigeria
The API splits Nigeria into
- States (36)
- Local Government Areas (LGAs) (775)
You can get more information about Nigeria by sending a GET request to api/country?search=nigeria. Assuming you don't know the id.
It should return something like this
Now you know the id, you can try this
The response will look like this
info
It would make a lot of sense to have something like api/countries/nigeria. But I asked a few more experienced backend persons and the reason it's not a good practice is that resource identifiers should be unique. What if the country decides to change their names🤷♀️? I'm pretty sure the ids will never change, so the search approach makes more sense.
States#
There are 36 states in Nigeria. You can get all of them by sending a GET request to the /api/countries/countryId/states endpoint. Here's an example
This will return something like this
Get state by Id#
You can get to a state by appending their Ids
You'll get the following response
Search, Sort, Filter states#
You can do pretty much anything on the States endpoint - Searching, Sorting, Filtering by following these guides. Here's an example of how you can sort by name and filter the name & description fields.
Your response would look like
LGAs#
States are futher split into local government areas (LGAs) and they can be accessed relative to the states. Here is an example that gets all the LGAs in Lagos state.
You'll get the following response.
Other Operations on LGAs#
LGA, like any other entity on WhereAPI, enables searching, pagination, sorting and ordering.
Pagination & Filtering#
We can combine the skip and take query params to request data progressively. Here's an example where we get the id and name of 4 LGAs in Abuja, but skip the first 2.
The first guid in this url is the id of Nigeria, while the second is the id of Abuja. They can pretty much be any Id of any other state.
Response