ApiCountries

Quick Start

Getting Started with APICountries

Introduction

APICountries is a free REST API service that provides detailed information about countries. This documentation will guide you through the basic usage and setup.

Terminology

For a better understanding of the docs, here are some common terminologies:

Endpoint: The specific URL path where an API can be accessed.

HTTP Method: The type of request to be made to the endpoint (e.g., GET, POST).

Status Code: The HTTP status code returned by the API, indicating the result of the request.

Usage Example in JS

To quickly start using APICountries, follow these steps to create a new project and integrate the API.

npm install axios

After installing Axios, you can start making requests to the APICountries API.

Create a file to fetch country data.

import axios from 'axios';
 
axios.get('https://www.apicountries.com/countries')
  .then(response => {
    console.log(response.data);
  })
  .catch(error => {
    console.error('Error fetching the country data:', error);
  });

Run the script and you will get a list of countries with detailed information.

Example Response

[
  {
    "name": "Afghanistan",
    "topLevelDomain": [".af"],
    "alpha2Code": "AF",
    "alpha3Code": "AFG",
    "callingCodes": ["93"],
    "capital": "Kabul",
    "altSpellings": ["AF", "Afġānistān"],
    "subregion": "Southern Asia",
    "region": "Asia",
    "population": 40218234,
    "latlng": [33, 65],
    "demonym": "Afghan",
    "area": 652230,
    "timezones": ["UTC+04:30"],
    "borders": ["IRN", "PAK", "TKM", "UZB", "TJK", "CHN"],
    "nativeName": "افغانستان",
    "numericCode": "004",
    "flags": {
      "svg": "https://upload.wikimedia.org/wikipedia/commons/5/5c/Flag_of_the_Taliban.svg",
      "png": "https://upload.wikimedia.org/wikipedia/commons/thumb/5/5c/Flag_of_the_Taliban.svg/320px-Flag_of_the_Taliban.svg.png"
    },
    "currencies": [
      {
        "code": "AFN",
        "name": "Afghan afghani",
        "symbol": "؋"
      }
    ],
    "languages": [
      {
        "iso639_1": "ps",
        "iso639_2": "pus",
        "name": "Pashto",
        "nativeName": "پښتو"
      },
      {
        "iso639_1": "uz",
        "iso639_2": "uzb",
        "name": "Uzbek",
        "nativeName": "Oʻzbek"
      },
      {
        "iso639_1": "tk",
        "iso639_2": "tuk",
        "name": "Turkmen",
        "nativeName": "Türkmen"
      }
    ],
    "translations": {
      "br": "Afghanistan",
      "pt": "Afeganistão",
      "nl": "Afghanistan",
      "hr": "Afganistan",
      "fa": "افغانستان",
      "de": "Afghanistan",
      "es": "Afganistán",
      "fr": "Afghanistan",
      "ja": "アフガニスタン",
      "it": "Afghanistan",
      "hu": "Afganisztán"
    },
    "flag": "https://upload.wikimedia.org/wikipedia/commons/5/5c/Flag_of_the_Taliban.svg",
    "regionalBlocs": [
      {
        "acronym": "SAARC",
        "name": "South Asian Association for Regional Cooperation"
      }
    ],
    "cioc": "AFG",
    "independent": true
  },
  ...
]
Status codeDescription
200Success
400Bad request
404Not found
429Rate limit exceeded

Last updated on

On this page

Star us on Github