Welcome to the World-Locations-API! This API provides information about continents, countries, states, and cities around the world. It is built using Node.js, Express, and PostgreSQL.
Follow these instructions to set up and run the WorldData API on your local machine.
-
Clone the repository:
git clone https://github.com/TarushGupta23/World-Locations-API cd World-Locations-API -
Install dependencies:
npm install
-
Run the API:
node index.js
The API will be running at http://localhost:3080. You can now make requests to the various endpoints.
Follow these steps to set up the PostgreSQL database for the WorldData API.
-
Open pgAdmin and connect to your PostgreSQL server.
-
Create a new database named
WorldData. -
Update the
index.jsfile with your PG-Admin password.
The data.sql file contains SQL commands to populate the database with initial data.
-
In pgAdmin, open a query tool for the
WorldDatadatabase. -
Copy the contents of the
data.sqlfile and paste them into the query tool. -
Execute the script to create tables and insert initial data.
Note: Ensure that the
pg_passwordin theindex.jsfile matches your PG-Admin password.
The database is now set up with initial data.
- Endpoint:
/all - Method:
GET - Description: Get a list of all locations, including continents, countries, states, and cities.
- Example Response:
[{"continent_code":"AS","name":"Asia","countries":[{"country_code":"IN","continent_code":"AS","name":"India","capital":"New Delhi","states":[{"state_id":"UP","country_code":"IN","name":"Uttar Pradesh","cities":[{"city_id":"LUK","state_id":"UP","name":"Lucknow"}]}]}]},{"continent_code":"EU","name":"Europe","countries":[{"country_code":"FR","continent_code":"EU","name":"France","capital":"Paris","states":[{"state_id":"IDF","country_code":"FR","name":"Île-de-France","cities":[{"city_id":"PAR","state_id":"IDF","name":"Paris"}]}]}]},{"continent_code":"NA","name":"North America","countries":[{"country_code":"US","continent_code":"NA","name":"United States","capital":"Washington, D.C.","states":[{"state_id":"CA","country_code":"US","name":"California","cities":[{"city_id":"SFO","state_id":"CA","name":"San Francisco"}]}]}]},{"continent_code":"SA","name":"South America","countries":[{"country_code":"BR","continent_code":"SA","name":"Brazil","capital":"Brasília","states":[{"state_id":"SP","country_code":"BR","name":"São Paulo","cities":[{"city_id":"SAO","state_id":"SP","name":"São Paulo"}]}]}]}]
- Example Response:
- Endpoint:
/continents - Method:
GET - Description: Get a list of all continents.
- Example Response:
[{"continent_code":"AS","name":"Asia"},{"continent_code":"EU","name":"Europe"},{"continent_code":"NA","name":"North America"},{"continent_code":"SA","name":"South America"}]
- Example Response:
- Endpoint:
/continent/:id/countries - Method:
GET - Description: Get all countries on a specific continent. Replace
:idwith the continent code.- Example Response:
[ { "country_code": "IN", "continent_code": "AS", "name": "India", "capital": "New Delhi" } ]
- Example Response:
- Endpoint:
/country/:id - Method:
GET - Description: Get details of a country by its country code. Replace
:idwith the country code.- Example Response:
{ "country_code": "IN", "continent_code": "AS", "name": "India", "capital": "New Delhi" }
- Example Response:
- Endpoint:
/country/:id/capital - Method:
GET - Description: Get capital city of a country by its country code. Replace
:idwith country code- Example Response:
{ "capital": "New Delhi" }
- Example Response:
- Endpoint:
/country/:id/states - Method:
GET - Description: Get states inside a specific country. Replace
:idwith the country code.- Example Response:
[ { "state_id": "UP", "country_code": "IN", "name": "Uttar Pradesh" } ]
- Example Response:
- Endpoint:
/state/:id/cities - Method:
GET - Description: Get cities inside a specific state. Replace
:idwith the state ID.- Example Response:
[ { "city_id": "LUK", "state_id": "UP", "name": "Lucknow" } ]
- Example Response:
- Endpoint:
/starts-with/:char - Method:
GET - Description: Get all locations which starts with given character sequence. replace
:charwith character sequence, use _ to simply get list of all locations' name
- Endpoint:
/ends-with/:char - Method:
GET - Description: Get all locations which ends with given character sequence. replace
:charwith character sequence, use _ to simply get list of all locations' name
- Endpoint:
/contains/:char - Method:
GET - Description: Get all locations which contains given character sequence. replace
:charwith character sequence, use _ to simply get list of all locations' name
-
Endpoint:
/location/:loc -
Method:
POST -
Description: Validate a location by providing the location name in the request body. Returns the location ID and type (continent, country, state, or city).
- Example Response:
{ "id": "IN", "type": "country" }
- Example Response:
Feel free to explore and integrate the WorldData API into your applications! If you have any questions or issues, please open an issue