https://github.com/pooranjoyb/places-api
An API created using NodeJS to serve data of all the cities of the World
https://github.com/pooranjoyb/places-api
api backend-api database javascript json-server nodejs server
Last synced: about 2 months ago
JSON representation
An API created using NodeJS to serve data of all the cities of the World
- Host: GitHub
- URL: https://github.com/pooranjoyb/places-api
- Owner: pooranjoyb
- License: mit
- Created: 2022-12-24T16:07:18.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2023-01-04T16:15:47.000Z (over 3 years ago)
- Last Synced: 2024-12-31T04:16:32.076Z (over 1 year ago)
- Topics: api, backend-api, database, javascript, json-server, nodejs, server
- Language: JavaScript
- Homepage: https://places-api-q5mi.onrender.com
- Size: 596 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Places-API
This is a NodeJS API containing data for all the Cities of the World. It uses a **JSON file** as the database which is available at **[Datahub](https://datahub.io/core/world-cities#data)**
## Documentation
You can use ***places-API*** to fetch data and use it in your projects.
The data is extracted from [geonames](https://geonames.org), a very exhaustive list of worldwide toponyms.
## Using the Fetch API
The Fetch API provides a JavaScript interface for accessing and manipulating parts of the protocol, such as requests and responses. It also provides a global fetch() method that provides an easy, logical way to fetch resources asynchronously across the network.
```js
fetch("https://places-api-q5mi.onrender.com/placesData")
.then(response => response.json())
.then(response => {
response.forEach(data => {
console.log(JSON.stringify(data, null, 2));
});
})
```
NOTE that the API will return an Array of Object hence JSON.stringify() method is used.
The following JSON file is available in the **/placesData** endpoint of the API
```json
{
"placesData": [
{
"country": "India",""
"geonameid": 1275339,
"name": "Mumbai",
"subcountry": "Maharashtra"
},
{
"country": "India",
"geonameid": 1261481,
"name": "New Delhi",
"subcountry": "NCT"
},
...
]
}
```
Data is served as an Array of Object from the server to the HTTP request
This [datapackage](https://dataprotocols.org/data-packages/) only list cities above 15,000 inhabitants. Each city is associated with its country and subcountry to reduce the number of ambiguities. Subcountry can be the name of a state (eg in United Kingdom or the United States of America) or the major administrative section (eg ‘‘region’’ in France’’).
## Usage
- Open Gitbash/Terminal/Windows-Powershell
- Copy the following command to clone this repository in your local storage:
```
git clone https://github.com/pooranjoyb/places-API.git
```
- Hit the Enter key.
It would take a few seconds to clone the repository onto your system.
**Note:** Cloning depends on the internet connection and the time would depend on your connection bandwidth. If Git is not able to clone due to a weak connection, it would display a fatal error and the user is requested to try again until the above message does not appear.
- Check in the local drive by navigating to it manually.
## Dependencies
- Nodemon (v2.0.20)
- JSON-server (v0.17.1)
Installation
npm install
- Run the following command to run the development server
```js
npm start
```
## Contribution
Contributions and Commits are apppreciated.
**ADD** your own city and create a **PULL REQUEST** to contribute
## Agreement
This data is provided "as is" without warranty or any representation of accuracy, timeliness or completeness.
## License
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.