GithubHelp home page GithubHelp logo

apilayer / restcountries Goto Github PK

View Code? Open in Web Editor NEW
2.2K 55.0 355.0 11.19 MB

Get information about countries via a RESTful API

Home Page: https://restcountries.eu

License: Mozilla Public License 2.0

Java 91.90% JavaScript 4.75% HTML 3.36%
rest-countries rest java countries rest-api

restcountries's Introduction

REST Countries

Get information about countries via a RESTful API https://restcountries.eu

Build Status

Donate!

The restcountries project has been acquired by apilayer, one of the leading providers of API microservices. We will keep supporting restcountries and providing it as a free solution for developers. We will finance this project fully and have turned off the donations feature.

Users

RESTCountries has over 1200 users, including:

TTÜ

Spotify International Pricing Index

Gorillaz

Wanderlust

Xero

FxPro

SKROSS

onefinestay

Much Better Adventures

Stay up-to-date

Follow RESTCountries on Twitter

Or subscribe to the mailing list

API Endpoints

Below are described the REST endpoints available that you can use to search for countries

All

https://restcountries.eu/rest/v2/all

Name

Search by country name. It can be the native name or partial name

https://restcountries.eu/rest/v2/name/{name}
https://restcountries.eu/rest/v2/name/eesti
https://restcountries.eu/rest/v2/name/united

Full Name

Search by country full name

https://restcountries.eu/rest/v2/name/{name}?fullText=true
https://restcountries.eu/rest/v2/name/aruba?fullText=true

Code

Search by ISO 3166-1 2-letter or 3-letter country code

https://restcountries.eu/rest/v2/alpha/{code}
https://restcountries.eu/rest/v2/alpha/co
https://restcountries.eu/rest/v2/alpha/col

List of codes

Search by list of ISO 3166-1 2-letter or 3-letter country codes

https://restcountries.eu/rest/v2/alpha?codes={code};{code};{code}
https://restcountries.eu/rest/v2/alpha?codes=col;no;ee

Currency

Search by ISO 4217 currency code

https://restcountries.eu/rest/v2/currency/{currency}
https://restcountries.eu/rest/v2/currency/cop

Language

Search by ISO 639-1 language code

https://restcountries.eu/rest/v2/lang/{et}
https://restcountries.eu/rest/v2/lang/es

Capital city

Search by capital city

https://restcountries.eu/rest/v2/capital/{capital}
https://restcountries.eu/rest/v2/capital/tallinn

Calling code

Search by calling code

https://restcountries.eu/rest/v2/callingcode/{callingcode}
https://restcountries.eu/rest/v2/callingcode/372

Region

Search by region: Africa, Americas, Asia, Europe, Oceania

https://restcountries.eu/rest/v2/region/{region}
https://restcountries.eu/rest/v2/region/europe

Regional Bloc

Search by regional bloc:

  • EU (European Union)
  • EFTA (European Free Trade Association)
  • CARICOM (Caribbean Community)
  • PA (Pacific Alliance)
  • AU (African Union)
  • USAN (Union of South American Nations)
  • EEU (Eurasian Economic Union)
  • AL (Arab League)
  • ASEAN (Association of Southeast Asian Nations)
  • CAIS (Central American Integration System)
  • CEFTA (Central European Free Trade Agreement)
  • NAFTA (North American Free Trade Agreement)
  • SAARC (South Asian Association for Regional Cooperation)
https://restcountries.eu/rest/v2/regionalbloc/{regionalbloc}
https://restcountries.eu/rest/v2/regionalbloc/eu

Response Example

https://restcountries.eu/rest/v2/alpha/col
[[{
	"name": "Colombia",
	"topLevelDomain": [".co"],
	"alpha2Code": "CO",
	"alpha3Code": "COL",
	"callingCodes": ["57"],
	"capital": "Bogotá",
	"altSpellings": ["CO", "Republic of Colombia", "República de Colombia"],
	"region": "Americas",
	"subregion": "South America",
	"population": 48759958,
	"latlng": [4.0, -72.0],
	"demonym": "Colombian",
	"area": 1141748.0,
	"gini": 55.9,
	"timezones": ["UTC-05:00"],
	"borders": ["BRA", "ECU", "PAN", "PER", "VEN"],
	"nativeName": "Colombia",
	"numericCode": "170",
	"currencies": [{
		"code": "COP",
		"name": "Colombian peso",
		"symbol": "$"
	}],
	"languages": [{
		"iso639_1": "es",
		"iso639_2": "spa",
		"name": "Spanish",
		"nativeName": "Español"
	}],
	"translations": {
		"de": "Kolumbien",
		"es": "Colombia",
		"fr": "Colombie",
		"ja": "コロンビア",
		"it": "Colombia",
		"br": "Colômbia",
		"pt": "Colômbia"
	},
	"flag": "https://restcountries.eu/data/col.svg",
	"regionalBlocs": [{
		"acronym": "PA",
		"name": "Pacific Alliance",
		"otherAcronyms": [],
		"otherNames": ["Alianza del Pacífico"]
	}, {
		"acronym": "USAN",
		"name": "Union of South American Nations",
		"otherAcronyms": ["UNASUR", "UNASUL", "UZAN"],
		"otherNames": ["Unión de Naciones Suramericanas", "União de Nações Sul-Americanas", "Unie van Zuid-Amerikaanse Naties", "South American Union"]
	}]
}]

Filter Response

You can filter the output of your request to include only the specified fields.

https://restcountries.eu/rest/v2/{service}?fields={field};{field};{field}
https://restcountries.eu/rest/v2/all?fields=name;capital;currencies

Sources

Similar projects

License

Mozilla Public License MPL 2.0

restcountries's People

Contributors

99darshan avatar brownsugar avatar danharper avatar egbakou avatar emartynov avatar epascalc avatar fayderflorez avatar julian-zehetmayr avatar lipis avatar luish avatar mikea1 avatar namnamir avatar oscerd avatar projectdelphai avatar sidati avatar soundasleep avatar thiagokoelho avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

restcountries's Issues

getting connection refused error

aught unhandled exception: java.lang.RuntimeException: org.apache.http.conn.HttpHostConnectException: Connect to restcountries.eu:443 [restcountries.eu/163.172.88.204] failed: Connection refused: connect

Pagination can also be added.

Just in case I don't wish to fetch all the countries in one go. I can set offset and limit to fetch the data. So that if user scrolls up more and is interested to see the list of countries it keeps on fetching the certain bunch of countries.

This project is categorised wrongfully as CSS

It's a kind of a silly issue of course but on the other hand I wouldn't find it.. but still!

Because of the two big CSS files this project is 87.4% CSS compare to the 10.9% Java which is actually what it's all about.. so just to improve a little bit that to give some credit to Java I think it's a good idea to remove at least the unminified version.. :)

I found it here and was wondering why this is a CSS project :)
https://github.com/trending?l=css

P.S. It's a pretty cool project by the way..!

translation

Hi there,

I am willing to add the Farsi translation to the db. Then Iranian and Afghan developers can use it :)

I don't know how it does work. Should I add it and ask for pull?

Ordering

Would be cool if it could be ordered by relevancy in the API itself.
e.g. if you search for UK, the first entry is "Ukraine", and the entry with the best relevancy is "United Kingdom" (what i'm actually after)

Thanks

Missing translations

Some translations are missing. I've taken the translations from Wikipedia, so I hope they are accurate.

if (country.alpha3Code == "BES")
{
    country.translations.it = "Bonaire, Saint-Eustache e Saba";
    country.translations.fr = "Bonaire, Saint-Eustache et Saba";
    country.translations.de = "Bonaire, Sint Eustatius und Saba";
}
else if (country.alpha3Code == "CUW")
{
    country.translations.it = "Curaçao";
    country.translations.fr = "Curaçao";
    country.translations.de = "Curaçao";
}
else if (country.alpha3Code == "SXM")
{
    country.translations.it = "Saint Martin (parte olandese)";
    country.translations.fr = "Saint Martin (partie néerlandaise)";
    country.translations.de = "Sint Maarten (niederl. Teil)";
}
else if (country.alpha3Code == "IRN")
{
    country.translations.fr = "Iran";
}

Currency and country error

Hi guys,

Very impressive API, but it seems that you may have a bug in your process. if you search for 2 digit alpha za (http://restcountries.eu/rest/alpha2/za) the currency comes up as SOS(Should be ZAR)

If you search under currency then South Georgia comes up with ZAR, I suspect this is a mismatch. (http://restcountries.eu/rest/currency/zar)

Under calling code 44 only Guernsey is returned when the UK also use this code. http://restcountries.eu/rest/callingcode/44
http://restcountries.eu/rest/alpha2/gb

Add Portugese to translations

"translations": {
    "de": "Kolumbien",
    "es": "Colombia",
    "fr": "Colombie",
    "ja": "コロンビア",
    "it": "Colombia",
    "pt": "Colômbia"
}

Port to Spring Boot

Hello,

First of all I must say this is an awesome project that is extremely useful!

I created of fork of the project (see here) where I have replaced JBoss Rest Easy with Spring Boot.
Feel free to use any parts of the code if you like them or ask me any questions you might have.
Of course I could issue a PR to your project, perhaps in some branch other than master so you can check it out.

Regards,
George

Geolocation support

Hi! First of all, great project!

Do you plan to extend this to include geolocation data as well? It would be really awesome if it also could be providing data from geonames.org, for instance.

Best regards, Baard

Search by demonym

Hi there,

Just came across this fantastic resource! I was looking for a solution where I am using another API which instead of country of origin, it only returns their nationality. I was hoping to find something where I could supply the nationality (demonym) and I could then find out the country. Are there any plans to make this available?

Thanks!

Provide a way to reduce output

It would be great to be able to pass a parameter to limit the fields provided in the response.

For example:

GET https://restcountries.eu/rest/v1/all?fields=name,capital,currencies
Accept: application/json

---

200 OK
Content-Type: application/json

[  
   {  
      "name":"Afghanistan",
      "capital":"Kabul",
      "currencies":[  
         "AFN"
      ]
   },
   {  
      "name":"Åland Islands",
      "capital":"Mariehamn",
      "currencies":[  
         "EUR"
      ]
   },
   {  
      "name":"Albania",
      "capital":"Tirana",
      "currencies":[  
         "ALL"
      ]
   }
   // ....
]

The ?fields=name,capital,currencies way of listing fields is very similar of the modern way the Facebook API does things. If you want to go the canonical way you could use something like this:

https://restcountries.eu/rest/v1/all?fields[]=name&fields[]=capital&fields[]=currencies

In both cases it would greatly reduce the output to only what's needed for the application and making it way faster to transfer the required content even for the full list of countries without wasting bandwidth for every field.

This would reduce the benefits of client-side and server-side caching, but it could reduce (or increase depending on the current implementation) the computational costs of the backend. ⚡

However the greatest benefit would be the reduced time to deliver the content to the client which I think is the bottleneck in most cases. 🚄

Thank you for the great service!

Cheers! 🍻

Missing timezones

Many countries are missing their timezones:

Åland Islands
American Samoa
Anguilla
Aruba
Bermuda
Bonaire, Sint Eustatius and Saba
British Indian Ocean Territory
United States Minor Outlying Islands
Cayman Islands
Christmas Island
Cocos (Keeling) Islands
Cook Islands
Falkland Islands (Malvinas)
Faroe Islands
French Guiana
French Polynesia
Gambia
Georgia
Gibraltar
Greenland
Guadeloupe
Guam
Guernsey
Isle of Man
Jersey
Martinique
Mayotte
Montserrat
Netherlands
New Caledonia
Niue
Norfolk Island
Northern Mariana Islands
Palestine, State of
Pitcairn
Puerto Rico
Republic of Kosovo
Réunion
Saint Barthélemy
Saint Helena, Ascension and Tristan da Cunha
Saint Martin (French part)
Saint Pierre and Miquelon
Sint Maarten (Dutch part)
South Georgia and the South Sandwich Islands
Svalbard and Jan Mayen
Tokelau
Turks and Caicos Islands
Wallis and Futuna
Western Sahara

status response

If there are no errors, could you send a 'status' key with 'OK' or something? it would help me much..

Search by Capital city end-point is Not working Correctly

Hi,

https://restcountries.eu/rest/v2/capital/gr

I have noticed that if you type in search field "gr" result will be "Croatia",
but capital of this country is Zagreb. Is this known issue ?

p.s. Thanks for such a great API !

Regards,
Dejan

UK calling code 44 only returns Guernsey

When searching for /name/united%20kingdom returns callingcode 44

[{
        "name": "United Kingdom",
        "currency": "GBP",
        "callingcode": "44",
        "capital": "London",
        "region": "Europe",
        "subregion": "Northern Europe",
        "altSpellings": "GB,Great Britain,England,UK,Wales,Scotland,Northern Ireland",
        "topLevelDomain": ".gb",
        "alpha2Code": "GB",
        "alpha3Code": "GBR",
        "isoNumericCode": "826"
    }]

but searching /callingcode/44 only returns

{
    "name": "Guernsey",
    "currency": "GBP",
    "callingcode": "44",
    "capital": "St. Peter Port",
    "region": "Europe",
    "subregion": "Northern Europe",
    "altSpellings": "GG",
    "topLevelDomain": ".gg",
    "alpha2Code": "GG",
    "alpha3Code": "GGY",
    "isoNumericCode": "831"
}

I think it's been assumed that the calling code is unique to one entity, but apparently it's not.

Add country regions, provinces, cities and related infos

It would be wonderful if it would be possible to retrieve regions, provinces and cities.

Something like:

// Regions of country
// /rest/alpha2/it/regions ->
{ regions:  [ "Abruzzi e Molise",
              "Basilicata",
              "Calabria",
              "Campania",
              "Emilia-Romagna",
              "Friuli-Venezia Giulia",
              "Lazio",
              "Liguria",
              "Lombardia",
              "Marche",
              "Piemonte",
              "Puglia",
              "Sardegna",
              "Sicilia",
              "Toscana",
              "Trentino-Alto Adige",
              "Umbria",
              "Valle d'Aosta",
              "Veneto" ] }

// Provinces of region
// /rest/alpha2/it/regions/Veneto/provinces ->
{ provinces: [ "Verona", "Venezia", ... ] }

// Cities of province
// /rest/alpha2/it/regions/Veneto/provinces/Venezia/cities ->
{ cities: [ { name: "Venezia", zip_codes: [ "30121", ... , "30176" ] }, 
            { name: "Chioggia", zip_codes: [ "30015" ] },
            { name: "San Donà di Piave", zip_codes: [ "30027" ] }, 
            ... ] }

// Cities of country by name
// /rest/alpha2/it/regions/Veneto/provinces/Venezia/cities ->
{ cities: [ { name: "Venezia", zip_codes: [ "30121", ... , "30176" ] }, 
            { name: "Chioggia", zip_codes: [ "30015" ] },
            { name: "San Donà di Piave", zip_codes: [ "30027" ] }, 
            ... ] }

Cities could have metadata like f.i. zip codes, which are very useful.

It is a huge work because recording and maintaining the whole list of regions, provinces and cities for every world country is hard, but it is a good target to be accomplished by an open source project.

First Example of country borders

In my branch dev https://github.com/ancosen/restcountries/tree/dev , i've added my idea to get the neighboring countries of a specified nation..

I've added a list "borders" in countries.json entry. I've made these changes only from Afghanistan to Antigua.

I've used the CCA3 as key in the borders list, so I was thinking if it is possible for @mledoze to add the borders field in his project https://github.com/mledoze/countries

If it's not possible in the next weeks I'll add this informations manually. Do you think this is a good solution? if yes, I'll submit a pull request.

Different endpoints for country codes are unnecessary

Hi, I think different endpoints for country codes are unnecessary.

Instead of having /rest/alpha2/ee and rest/alpha3/col, you should be able to decide which by looking at the character number in the string. ("ee" is two characters, it's alpha2, and col is 3, so it's alpha3)

Also, alpha{2|3} part is not that necessary either, if what comes after /rest/ is not {name|currency|callingcode|capital}, it's can be interpret as country code.

Good job though. I don't know enough Java to send a PR with these, I wish I could.

Public API extremely slow / inaccessible

API requests seem to be somewhere between "extremely slow" and "totally inaccessible". This one took about 54 seconds:

$ time curl https://restcountries.eu/rest/v1/all
... long pause ...
[{"name":"Afghanistan"... etc }]

curl https://restcountries.eu/rest/v1/all  0.02s user 0.01s system 0% cpu 54.300 total

Does the API includes cities?

Can't understand if there are cities as well.
Don't you know by chance where may I find either downloadable or as API a "country => all its cities" data?

Missing ISO countries

Hi,

Great API!

I'm only missing 3 ISO countries: Antarctica, Holy See and Virgin Islands, U.S.. For some countries, I also see a different name than the ISO name. For example: Vietnam (API) vs Viet Nam (ISO). Is this done on purpose, or should these names also be updated?

Regards,
Joost

United States Minor Outlying Islands missing latlng data

United States Minor Outlying Islands is the only entry in the list that does not have any latlng data. Perhaps it was omitted because the territories are very, very far apart from each other and no single spot would make sense, but so are the islands of Kiribati and Federated States of Micronesia, for example, and those entries include latlng data.

If you'd like to include latlng data for United States Minor Outlying Islands, I might suggest using the coordinates of Wake Island, its largest territory:

lat: 19.3,
lng: 166.633333

Love the project! Thanks much.

CORS issue

When connecting to the API using Ajax I get the following error message
XMLHttpRequest cannot load https://restcountries.eu/rest/v2/name/m. Request header field Content-Type is not allowed by Access-Control-Allow-Headers in preflight response.

It seems that the API needs to have CORS headers enabled.

Oman - Romania

When calling the https://restcountries.eu/rest/v2/name/{name} API, I get an error on Oman. The json response I get looks like this:
[{"name":"Oman","topLevelDomain":[".om"],"alpha2Code":"OM","alpha3Code":"OMN","callingCodes":["968"],"capital":"Muscat","altSpellings":["OM","Sultanate of Oman","Salṭanat ʻUmān"],"region":"Asia","population":4420133,"latlng":[21.0,57.0],"demonym":"Omani","area":309500.0,"gini":null,"timezones":["UTC+04:00"],"borders":["SAU","ARE","YEM"],"nativeName":"عمان","numericCode":"512","currencies":[{"code":"OMR","name":"Omani rial","symbol":"ر.ع."}],"languages":[{"iso639_1":"ar","iso639_2":"ara","name":"Arabic","nativeName":"العربية"}],"translations":{"de":"Oman","es":"Omán","fr":"Oman","ja":"オマーン","it":"oman","br":"Omã","pt":"Omã"}},{"name":"Romania","topLevelDomain":[".ro"],"alpha2Code":"RO","alpha3Code":"ROU","callingCodes":["40"],"capital":"Bucharest","altSpellings":["RO","Rumania","Roumania","România"],"region":"Europe","population":19861408,"latlng":[46.0,25.0],"demonym":"Romanian","area":238391.0,"gini":30.0,"timezones":["UTC+02:00"],"borders":["BGR","HUN","MDA","SRB","UKR"],"nativeName":"România","numericCode":"642","currencies":[{"code":"RON","name":"Romanian leu","symbol":"lei"}],"languages":[{"iso639_1":"ro","iso639_2":"ron","name":"Romanian","nativeName":"Română"}],"translations":{"de":"Rumänien","es":"Rumania","fr":"Roumanie","ja":"ルーマニア","it":"Romania","br":"Romênia","pt":"Roménia"}}]

You can check it here:
https://restcountries.eu/rest/v2/name/oman

Same thing happens for the equivalent V1 API.
I have an app where I click on a country and get the capital , population and demonym.
Problem is when I click on Oman, it iterates 2 times and gets Romania's data instead.
To reproduce it, you can go to this codepen and : click on Asia, then on Oman and you will see what I am talking about: http://codepen.io/ioiomano/pen/26e7e3a0bea5edeede771b4916888ebb
All the best and thank you for sharing your work,
Ioana Manoliu

Official Languages - Philippines

The API only mentions English as the official language for the Philippines. Filipino(Tagalog) is their first official language and English is second. Been getting nagged at members who are natives to the Philippines lol.

Just wanted to contribute a little here. And thank you for this API!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.