A simple project demonstrating the usage of the Programming Hero Countries API endpoints. Provides information about all countries, specific country by code or name, or by language.
These are the Programming Hero APIs this project interacts with:
Endpoint | Purpose |
---|---|
/api/all |
Fetches data on all countries. |
/api/alpha/{code} |
Fetches data about a country by its ISO alpha-code (e.g. 116 ). |
/api/lang/{language} |
Fetches countries where the specified language is spoken. |
/api/name/{name} |
Fetches data on a country (or countries) by its common name. |
- URL:
GET /api/all
- Description: Returns an array of all countries and their information: name, code, region, population, etc.
-
URL:
GET /api/alpha/{code}
-
Parameter:
code
(string or numeric) — the ISO alpha code of the country (e.g.116
)
-
Description: Returns detailed data for the country identified by that ISO code.
-
URL:
GET /api/lang/{language}
-
Parameter:
language
(string) — the language name (e.g.english
)
-
Description: Returns the list of countries that speak the given language.
-
URL:
GET /api/name/{name}
-
Parameter:
name
(string) — the common name of the country (e.g.bangladesh
)
-
Description: Return data for country or countries whose name matches the supplied parameter.
Here’s how you might use these endpoints in your app (JavaScript / fetch example):
// Fetch all countries
fetch("https://openapi.programming-hero.com/api/all")
.then((res) => res.json())
.then((data) => console.log(data));
// Fetch country by ISO code
fetch("https://openapi.programming-hero.com/api/alpha/116")
.then((res) => res.json())
.then((data) => console.log(data));
// Fetch countries by language
fetch("https://openapi.programming-hero.com/api/lang/english")
.then((res) => res.json())
.then((data) => console.log(data));
// Fetch country by name
fetch("https://openapi.programming-hero.com/api/name/bangladesh")
.then((res) => res.json())
.then((data) => console.log(data));
To set up this project locally:
-
Clone the repository
-
Install dependencies (if any)
- e.g.
npm install
oryarn install
- e.g.
-
Create any configuration file if needed (e.g. for environment variables)
-
Run the app
- e.g.
npm start
- e.g.
Here are example shapes of JSON responses you may get (fields may vary):
[
{
"name": "Afghanistan",
"alpha2Code": "AF",
"alpha3Code": "AFG",
"capital": "Kabul",
"region": "Asia",
"population": 40218234
// ... more fields
},
{
"name": "Albania",
"alpha2Code": "AL",
"alpha3Code": "ALB",
"capital": "Tirana",
"region": "Europe",
"population": 2877797
// ...
}
// ... many more
]
{
"name": "Country-Name",
"alpha2Code": "XX",
"alpha3Code": "XXX",
"capital": "...",
"region": "...",
"population": ...,
// ... other details
}
[
{
"name": "United Kingdom",
"alpha2Code": "GB",
"capital": "London"
// ...
},
{
"name": "United States of America",
"alpha2Code": "US",
"capital": "Washington D.C."
// ...
}
// ... more countries
]
[
{
"name": "Bangladesh",
"alpha2Code": "BD",
"alpha3Code": "BGD",
"capital": "Dhaka",
"region": "Asia",
"population": ...,
// ...
}
]