Getting A Country's Regions
Cache the region list per country to avoid needless hits on the service. We recommend doing this lazily (as needed at runtime) using something like an LRU cache, since in a given session, the user isn't likely to care about all regions for every country.
Below we get the regions for the United States.
GraphQL
curl --request POST \ --url https://geodb-cities-graphql.p.rapidapi.com/ \ --header 'content-type: application/json' \ --header 'x-rapidapi-host: geodb-cities-graphql.p.rapidapi.com' \ --header 'x-rapidapi-key: YOUR_API_KEY' \ --data '{"query":"QUERY"}'
Where QUERY:
{ country(id:"US") { regions(first:10) { totalCount pageInfo { startCursor endCursor hasNextPage } edges { node { name } } } } }
REST
curl --get --include 'https://wft-geo-db.p.rapidapi.com/v1/geo/countries/US/regions?offset=0&limit=10' \ -H 'x-rapidapi-key: YOUR_API_KEY' \ -H 'x-rapidapi-host: wft-geo-db.p.rapidapi.com'