The Population Management API is a Restful API for managing population records of locations. Locations can be nested in other locations.
The API is set up in such a way that if a location has sub locations, it's Male, Female and Total are equal to the sum of sublocations for the different locations. If a location doesn't have any sublocations, its population is equivalent to what was passed when creating it.
Considering that locations can be nested in other locations. We have limited updating a sublocation's parent. We advise the user to delete the location and create a new one.
Deleting a parent location deletes all it's children / sublocations.
This API has been developed and tested on macOS High Sierra Version 10.13.6
- Install Nodejs 8 or above
- Install Mongo DB (guide here)
- Clone the repo onto your computer
- Update the
env
file with your environment variables - Install packages
npm install
- Run
./run.sh
to start the application
- Location - creation, update, deletion, getting single location and all locations.
- Nested / Sub Location - creation, update, deleting, and retrieving sublocations
Type | API Endpoint | Description |
---|---|---|
POST | /locations |
Creates a new parent location. Requires male, female as number payloads and name as string Sample Payload { Sample Response { |
POST | /locations |
Creates a new nested / sublocation location. Requires male, female as number payloads and name and parent location as string Sample Payload { Sample Response { |
GET | /locations |
Gets all locations. Returns parent and nested locations. Sample Response [ |
GET | /locations/:id |
Get Single Location by id Sample Response { |
PUT | /locations/:id |
Update location name, female and male population Sample Payload { Sample Response { |
DELETE | /locations/:id |
Delete location. Replace location id in the url with the actually ID of the location. Sample Response { |
The Application tests can be executed by running the command below on your console.
npm test