MartinsOnuoha / countriesNowAPI

CountriesNow is an Open source API for retrieving geo-information for countries, including their states, cities, population, etc. 🌎
http://countriesnow.space
MIT License
179 stars 55 forks source link

Question #46

Closed fcpauldiaz closed 3 years ago

fcpauldiaz commented 3 years ago

is there a way to get 2 iso country code instead of 3 ?

iambenkay commented 3 years ago

Could you explain more what you mean?

fcpauldiaz commented 3 years ago

api returns iso3 country code. like USA, but can it be configured to return iso2 like US?

MartinsOnuoha commented 3 years ago

@fcpauldiaz Currently, there are endpoints you can use to get iso2 and iso3 of any country. For instance, sending a GET to https://countriesnow.space/api/v0.1/countries/iso would return a response like this:

  "error": false,
  "msg": "countries and ISO codes retrieved",
  "data": [
    {
      "name": "Afghanistan",
      "Iso2": "AF",
      "Iso3": "AFG"
    },
    {
      "name": "United States",
      "Iso2": "US",
      "Iso3": "USA"
    },
  ],
 ...

Here you have a list of all the countries and their iso2 and iso3 codes. If you need a single country, just change the request type to POST using the same endpoint https://countriesnow.space/api/v0.1/countries/iso and you'll get a single country's iso2 and iso3 code.

curl -d '{"country":"nigeria"}' -H "Content-Type: application/json" -X POST https://countriesnow.space/api/v0.1/countries/iso

Response:

{
  "error": false,
  "msg": "country's ISO code retrieved",
  "data": {
    "name": "Nigeria",
    "Iso2": "NG",
    "Iso3": "NGA"
  }
}

Does this answer your question?

fcpauldiaz commented 3 years ago

Yes, thanks!