Code Monkey home page Code Monkey logo

rest-countries-node's Introduction

Build Status npm version

Rest Country Node

A Node.js wrapper library around the API provided by https://restcountries.eu .

Usage

var RestCountries = require('rest-countries-node');
restCountries = new RestCountries;

getAll()

Returns all countries information:

restCountries.getAll()
  .then(response => {
    /*...*/
  });

findByName()

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

restCountries.findByName('france')
  .then(response => {
    /*
      [
        {
          "alpha2Code": "FR",
          "alpha3Code": "FRA",
          "altSpellings": [
            "FR",
            "French Republic",
            "République française"
          ],
          ...
        }
      ]
    */
  });

findByFullName()

Search by country full name:

restCountries.findByFullName('france')
  .then(response => {
    /*
      [
        {
          "alpha2Code": "FR",
          "alpha3Code": "FRA",
          "altSpellings": [
            "FR",
            "French Republic",
            "République française"
          ],
          ...
        }
      ]
    */
  });

findByIsoCountryCode()

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

restCountries.findByIsoCountryCode('bg')
  .then(response => {
    /*
      {
        "alpha2Code": "BG",
        "alpha3Code": "BGR",
        "altSpellings": [
          "BG",
          "Republic of Bulgaria",
          "Република България"
        ],
        ...
      }
    */
  });

findByIsoCountryCodes()

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

restCountries.findByIsoCountryCodes('pl;gb;it')
  .then(response => {
    /*
      [
        {
          "alpha2Code": "PL",
          "alpha3Code": "POL",
          "altSpellings": [
            "PL",
            "Republic of Poland",
            "Rzeczpospolita Polska"
          ],
          ...
        },
        {
          "alpha2Code": "GB",
          "alpha3Code": "GBR",
          "altSpellings": [
            "GB",
            "UK",
            "Great Britain"
          ],
          ...
        },
        {
          "alpha2Code": "IT",
          "alpha3Code": "ITA",
          "altSpellings": [
            "IT",
            "Italian Republic",
            "Repubblica italiana"
          ],
          ...
        }
      ]
    */
  });

findByCurrency()

Search by ISO 4217 currency code:

restCountries.findByCurrency('pln')
  .then(response => {
    /*
      [
        {
          "alpha2Code": "PL",
          "alpha3Code": "POL",
          "altSpellings": [
            "PL",
            "Republic of Poland",
            "Rzeczpospolita Polska"
          ],
          ...
        }
      ]
    */
  });

findByLanguageCode()

Search by ISO 639-1 language code:

restCountries.findByLanguageCode('it')
  .then(response => {
    /*
      [
        {
          "alpha2Code": "VA",
          "alpha3Code": "VAT",
          "altSpellings": [
            "Sancta Sedes",
            "Vatican",
            "The Vatican"
          ],
          ...
        },
        {
          "alpha2Code": "IT",
          "alpha3Code": "ITA",
          "altSpellings": [
            "IT",
            "Italian Republic",
            "Repubblica italiana"
          ],
          ...
        }
      ]
    */
  });

findByCapitalCity()

Search by capital city:

restCountries.findByCapitalCity('tallinn')
  .then(response => {
    /*
      [
        {
          "alpha2Code": "EE",
          "alpha3Code": "EST",
          "altSpellings": [
            "EE",
            "Eesti",
            "Republic of Estonia",
            "Eesti Vabariik"
          ],
          ...
        }
      ]
    */
  });

findByCallingCode()

Search by calling code:

restCountries.findByCallingCode('377')
  .then(response => {
    /*
      [
        {
          "alpha2Code": "MC",
          "alpha3Code": "MCO",
          "altSpellings": [
            "MC",
            "Principality of Monaco",
            "Principauté de Monaco"
          ],
          ...
        }
      ]
    */
  });

findByRegion()

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

restCountries.findByRegion('oceania')
  .then(response => {
    /*
      [
        {
          "alpha2Code": "AS",
          "alpha3Code": "ASM",
          "altSpellings": [
            "AS",
            "Amerika Sāmoa",
            "Amelika Sāmoa",
            "Sāmoa Amelika"
          ],
          ...
        },
        ...
      ]
    */
  });

getAllGroupedBySubRegion()

Returns a list of countries grouped by subregions:

restCountries.getAllGroupedBySubRegion()
  .then(response => {
    /*
      { "southern-europe":
        [
          {
            "alpha2Code": "ES",
            "alpha3Code": "ESP",
            "altSpellings": [
              "ES",
              "Kingdom of Spain",
              "Reino de España"
            ],
            ...
          },
          ...
        ],
        "south-america":
        [
          {
            "alpha2Code": "CO",
            "alpha3Code": "COL",
            "altSpellings": [
              "CO",
              "Republic of Colombia",
              "República de Colombia"
            ],
            ...
          },
          ...
        ],
        ...
      }
    */
  });

findCountryFlagByCountryName()

Returns the flag for a given country :

restCountries.findCountryFlagByCountryName('Spain')
  .then(response => {
    /*
      {
        "countryName": "Spain",
        "flag": "https://restcountries.eu/data/esp.svg"
      }
    */
  });

findCountryByForeignName()

Returns the flag for a given country :

restCountries.findCountryByForeignName('スペイン')
  .then(response => {
    /*
      {
        "alpha2Code": "ES",
        "alpha3Code": "ESP",
        "altSpellings": [
          "ES",
          "Kingdom of Spain",
          "Reino de España"
        ],
        ...
      }
    */
  });

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.