This REST API registers and returns data of locations. I've used MongoDB as the database of this project.
You need to have Node.js (> 8) installed and run 'npm install' on Terminal before using.
$ npm run test
$ npm run start
$ nodemon -L
This API has 3 endpoints:
Use header 'content-type' with value 'application/json' on request;
Do not use 'names' as the location name.
Send the body (JSON) of the request with the following fields: latitude (number), longitude (number) and additionalData (optional JSON object);
The data will be registered on MongoDB. If this location name already exists, the document will be updated. In both cases, create or update, the API will return a 201 HTTP code in case of success.
Use header 'apitoken' with value 'internal' on request;
The API will return an array containing all registered location names.
Use header 'apitoken' with value 'internal' on request;
The API will return the location data and its distance to another fixed location in km. The distance is calculated using the Haversine formula (algorithm reference: https://stackoverflow.com/questions/27928/calculate-distance-between-two-latitude-longitude-points-haversine-formula). Latitude/longitude of the fixed location: 52.502931/13.408249.