Country API

The Country API provides useful statistics about every country in the world.

/v1/country

HTTP GET

Get country data from given parameters. Returns a list of country statistics that satisfy the parameters.

Parameters

name (optional) - Plain English name, 2-letter ISO-3166 alpha-2, or 3-letter ISO-3166 alpha-3 code of country.

currency (optional) - 3-letter currency code of country (e.g. USD).

min_gdp (optional) - minimum gross domestic product (GDP) of country, in US Dollars.

max_gdp (optional) - maximum gross domestic product (GDP) of country, in US Dollars.

min_population (optional) - minimum population of country.

max_population (optional) - maximum population of country.

min_area (optional) - minimum surface area of country in km2.

max_area (optional) - maximum surface area of country in km2.

min_unemployment (optional) - minimum unemployment rate in %.

max_unemployment (optional) - maximum unemployment rate in %.

min_gdp_growth (optional) - minimum GDP growth rate in %.

max_gdp_growth (optional) - maximum GDP growth rate in %.

min_infant_mortality (optional) - minimum infant mortality rate in %.

max_infant_mortality (optional) - maximum infant mortality rate in %.

min_fertility (optional) - minimum fertility rate in %.

max_fertility (optional) - maximum fertility rate in %.

min_urban_pop_rate (optional) - minimum urban population rate in %.

max_urban_pop_rate (optional) - maximum urban population rate in %.

limit (optional) - How many results to return. Must be between 1 and 30. Default is 5.

Headers

X-Api-Key (required) - API Key associated with your account.

Sample Request URL

Live Demo!

https://api.api-ninjas.com/v1/country?name=

Sample Response

[
  {
    "gdp": "20580223",
    "sex_ratio": "97.9",
    "surface_area": "9833517",
    "life_expectancy_male": "76.3",
    "unemployment": "3.9",
    "imports": "2567490",
    "homicide_rate": "5",
    "currency": {
      "code": "USD",
      "name": "Us Dollar"
    },
    "iso2": "US",
    "gdp_growth": "2.9",
    "employment_services": "79",
    "urban_population_growth": "0.9",
    "secondary_school_enrollment_female": "98.7",
    "employment_agriculture": "1.3",
    "capital": "Washington, D.C.",
    "co2_emissions": "4761.3",
    "forested_area": "33.9",
    "tourists": "79746",
    "exports": "1644280",
    "life_expectancy_female": "81.3",
    "post_secondary_enrollment_female": "102.0",
    "post_secondary_enrollment_male": "75.0",
    "primary_school_enrollment_female": "101.4",
    "infant_mortality": "5.8",
    "secondary_school_enrollment_male": "99.2",
    "threatened_species": "1655",
    "population": "331003",
    "urban_population": "82.5",
    "employment_industry": "19.7",
    "name": "United States",
    "pop_growth": "0.6",
    "region": "Northern America",
    "pop_density": "36.2",
    "internet_users": "87.3",
    "gdp_per_capita": "62917.9",
    "fertility": "1.8",
    "refugees": "1043.2",
    "primary_school_enrollment_male": "102.2"
  }
]

import requests

api_url = 'https://api.api-ninjas.com/v1/country?name=United States'
response = requests.get(api_url, headers={'X-Api-Key': 'YOUR_API_KEY'})
if response.status_code == requests.codes.ok:
    print(response.text)
else:
    print("Error:", response.status_code, response.text)
$.ajax({
    method: 'GET',
    url: 'https://api.api-ninjas.com/v1/country?name=United States',
    headers: { 'X-Api-Key': 'YOUR_API_KEY'},
    contentType: 'application/json',
    success: function(result) {
        console.log(result);
    },
    error: function ajaxError(jqXHR) {
        console.error('Error: ', jqXHR.responseText);
    }
});
const request = require('request');

request.get({
  url: 'https://api.api-ninjas.com/v1/country?name=United States',
  headers: {
    'X-Api-Key': 'YOUR_API_KEY'
  },
}, function(error, response, body) {
  if(error) return console.error('Request failed:', error);
  else if(response.statusCode != 200) return console.error('Error:', response.statusCode, body.toString('utf8'));
  else console.log(body)
});
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;

import com.fasterxml.jackson.databind.ObjectMapper;

URL url = new URL("https://api.api-ninjas.com/v1/country?name=United States");
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestProperty("accept", "application/json");
InputStream responseStream = connection.getInputStream();
ObjectMapper mapper = new ObjectMapper();
JsonNode root = mapper.readTree(responseStream);
System.out.println(root.path("fact").asText());
let url = URL(string: "https://api.api-ninjas.com/v1/country?name=United States"!)!
var request = URLRequest(url: url)
request.setValue("YOUR_API_KEY", forHTTPHeaderField: "X-Api-Key")
let task = URLSession.shared.dataTask(with: request) {(data, response, error) in
    guard let data = data else { return }
    print(String(data: data, encoding: .utf8)!)
}
task.resume()
If your programming language is not listed in the Code Example above, you can still make API calls by using a HTTP request library written in your programming language and following the above documentation.