API Documentation for NationNode

Base URL: https://countries-api-abhishek.vercel.app/

Overview

This API provides information about countries, including a list of all countries and the details of individual countries. It supports endpoints for retrieving all countries or querying a specific country by its name.

Endpoints

1. GET /countries

Description: Retrieves a list of all countries.

Request:

GET /countries

Response:

Success Response:

{
  "message": "Successfully retrieved all countries",
  "data": [ /* Array of country objects */ ],
  "statusCode": 200
}
          

Error Response:

{
  "message": "No country data available",
  "error": true,
  "statusCode": 404,
  "details": "The countries data is either not loaded or unavailable at the moment. Please check the data source or try again later."
}
          

2. GET /countries/:countryname

Description: Retrieves the details of a country by its name. The :countryname parameter should be specified in the URL.

Request:

GET /countries/:countryname

Response:

Success Response:

{
  "message": "Successfully retrieved data for ''",
  "data": { /* Country details object */ },
  "statusCode": 200
}
          

Error Responses:

Country Name Missing (Bad Request):

{
  "message": "Country name is required",
  "error": true,
  "statusCode": 400,
  "details": "The country name must be specified in the URL as part of the request. Please provide a valid country name."
}
          

Country Not Found (Not Found):

{
  "message": "Country with name '' not found",
  "error": true,
  "statusCode": 404,
  "details": "No country data was found for ''. Please check the country name for any typos or refer to the list of available countries."
}
          

3. Fallback Route for Undefined Endpoints

Description: If an undefined or incorrect route is accessed, the fallback route provides an error response.

Request:

Any unsupported HTTP method or route.

Response:

{
  "message": "Route not found",
  "error": true,
  "statusCode": 404,
  "details": "The endpoint you are trying to access does not exist. Please check the URL and try again."
}
          

Error Status Codes Overview

Example Request

1. Get all countries:

GET https://countries-api-abhishek.vercel.app/countries

2. Get details for a specific country (e.g., India):

GET https://countries-api-abhishek.vercel.app/countries/India

Testing the API

To test the API locally, you can use tools like Postman or cURL. Here’s how you can test using cURL:

Get all countries:

curl https://countries-api-abhishek.vercel.app/countries

Get details for a specific country (e.g., India):

curl https://countries-api-abhishek.vercel.app/countries/India

Link to API Website:

API Documentation Website: https://countries-api-abhishek.vercel.app/