An integration of REST Countries API using NestJS, is a robust and scalable framework for building server-side applications using JavaScript or TypeScript. This particular application was built using TypeScript.
- API Endpoints:
- Get all countries
- Get countries by name
- Get countries by cca2, ccn3, cca3 or cioc country code
- Get countries by country code
- Get countries by currency
- Get countries by language
- Get countries by capital
- Get countries by region
- Get countries by subregion
- Get countries by translation
- Get countries filtering out all except what is specified e.g name, currency, language etc.
- Logging:
- Captures important events, request, and errors.
- NodeJs
- NestJS
git clone https://github.com/Daud94/shortlet.git
Create a .env
file in the root directory with the following content:
REST_COUNTRIES=https://restcountries.com/v3.1/
API_PORT= # or any sepcified port of your choice
REST_COUNTRIES
Base url of REST Countries
API_PORT
is the port number you want the app to run on e.g 3000.
Install all dependencies from the package.json
file:
npm install
Run the application:
npm run start:dev
All API endpoints are documented with Swagger and can be accessed from BASE_URL/api
e.g localhost:API_PORT/api
.
APIs
- GET
/countries/all
fetches all countries. Query response is optimised through in-memory caching. A total of 250 records is returned from the original response but now cached. Cache TTL is set 24hrs. - GET
countries/name/{name}
fetches countries by name path param. - GET
countries/alpha
fetches countries by cca2, ccn3, cca3 or cioc country code. e.g + 'countries/alpha?codes=170&codes=no&codes=est&codes=pe
.' - GET
countries/code/{code}
fetches countries by code path param. - GET
countries/currency/{currency}
fetches countries by currency path param. - GET
countries/language/{lang}
fetches countries by lang(language) path param. - GET
countries/capital/{capital}
fetches countries by capital path param. - GET
countries/region/{region}
fetches countries by region path param. - GET
countries/subregion/{subregion}
fetches countries by subregion path param. - GET
countries/translation/{translation}
fetches countries by subregion path param. - GET
countries/all/filter
fetches all countries filterable by fields query param e.gcountries/all/filter?fields=name&fields=currencies
.fields
value can be any of the following and any numbers of them separated by '&':- name
- currencies
- code
- language
- capital
- region
- subregion
- translation