REST Countries

REST Countries

  • Category: Open Data


Explore the World with the REST Countries API

Are you looking to access data about countries from around the world? REST Countries API is here to help! This public API allows developers to access a collection of information about countries covering topics like geography, demographics, and economics.

The REST Countries API provides data in JSON format for over 250 countries, with information on everything from country codes to national currencies. Here are some examples of how you can use the API to access and parse data in JavaScript.

Prerequisites

Make sure you have the following installed:

  • Node.js and npm

Making API Requests

Let's get started!

Installation

First, make sure to install the node-fetch package by typing the command below into your terminal:

$ npm install node-fetch

This package will allow you to make HTTP requests using JavaScript.

Example 1: List of All Countries

To retrieve a list of all the countries included in the API, you can use the following code:

const fetch = require('node-fetch');
 
fetch('https://restcountries.eu/rest/v2/all')
  .then(response => response.json())
  .then(data => console.log(data));

Example 2: Specific Country Data

To retrieve information about a specific country from the API, use the following code:

const fetch = require('node-fetch');
 
fetch('https://restcountries.eu/rest/v2/name/united kingdom')
  .then(response => response.json())
  .then(data => console.log(data));

The above code will return information on the United Kingdom.

Example 3: Country Capital

To retrieve the capital city of a specific country using the REST Countries API, use the following code:

const fetch = require('node-fetch');
 
fetch('https://restcountries.eu/rest/v2/name/united kingdom?fields=capital')
  .then(response => response.json())
  .then(data => console.log(data[0].capital));

This will return 'London', the capital city of the United Kingdom.

Example 4: Currency Exchange Rates

To return the exchange rate for a specific country, use the following code:

const fetch = require('node-fetch');
 
fetch('https://restcountries.eu/rest/v2/currency/gbp')
  .then(response => response.json())
  .then(data => console.log(data));

Example 5: Country Flag

To retrieve the flag image for a specific country, use the following code:

const fetch = require('node-fetch');
 
fetch('https://restcountries.eu/rest/v2/name/united kingdom?fields=flag')
  .then(response => response.json())
  .then(data => console.log(data[0].flag));

This will return the URL for the flag image for the United Kingdom.

Conclusion

The REST Countries API is a powerful tool that can help you access a wide range of information about countries around the world. With the examples above, you should now have a better understanding of how to make API requests using JavaScript and how to parse the resulting data. Happy exploring!

Visit to REST Countries website

Similar APIs of Open Data

Sweat & Toil

Sweat & Toil

Open Data

Integrates information on child labor and forced labor taken from the reports “Findings on the Worst Forms of Child Labor,” “List of Goods Produced by Child Labor or Forced Labor,” and “List of Products Produced by Forced or Indentured Child Labor.”

childlaborcrime

FBI Wanted API

FBI Wanted API

Open Data

The FBI Wanted API is designed to help developers easily get information on the FBI Wanted program. The API is a simple REST endpoint that accepts query parameters for options and returns application/json responses.

criminalwantedfbi

Jailbase

Jailbase

Open Data

Get access to a database of mugshots and arrest data sourced from many counties across the U.S. JailBase.com has an easy to use web api so your website or application can access our extensive county jail inmate data. Using the API, you can search for arrested and booked individuals in county jails. The web service uses a REST interface to make calls and returns results in JSON (JSONP is also supported). Calls to the webservice do not require a developer key, however they are rate limited.

crimewantedarrests

Creative Commons Catalog

Creative Commons Catalog

Open Data

The Creative Commons Catalog API ('cccatalog-api') is a system that allows programmatic access to public domain digital media. It is our ambition to index and catalog billions of Creative Commons works, including articles, songs, videos, photographs, paintings, and more. Using this API, developers will be able to access the digital commons in their own applications.

creativecommonscatalog

Bible API

Bible API

Open Data

RESTful Bible API with 7 versions, 4 languages and multiple features

bibledataapi

Open Topo Data

Open Topo Data

Open Data

Elevation and ocean depth for a latitude and longitude

opentopodata

Star Wars API

Star Wars API

Open Data

Star Wars API with tons of information on the Star Wars universe. API lists you the planets, spaceships, vehicles, people, films and species. Form all Sever Star War films. Also has the "force awakens" data. You get hair color, skin color and eye color of the mentioned characters.

starwarsforce

Taylor REST

Taylor REST

Open Data

REST API for random Taylor Swift quotes

taylorrestjson

Faker API

Faker API

Open Data

Faker API it's a collection of completely free APIs that helps web developers and web designers generate fake data in a fast and easy way. No registration is required. No tokens, no authentication. Every resource allows to choose the API language by "_locale" parameter and also allows to select the number of rows requested by "_quantity" parameter. Max 1000 rows.

opendatafake

Image Charts

Image Charts

Open Data

The Image-Charts API returns a chart image in response to a URL GET or POST request. The API can generate many kinds of charts, from pie or line charts to bar charts and radars. All the information about the chart that you want, such as chart data, size, colors, and labels, are part of the URL.

chartopenapi