Simple homework project for http endpoints in nodejs.
This install guide assumes that you have at least MongoDB, node.js, npm and git installed on your system. For installation instructions of the above packages please consult your distribution's help or your system administrator.
Download the package source from github to your selected directory.
git clone https://github.com/torgaja/nodejs_homework.git
Use native package manager of node.js npm to install all dependencies of the package in the root dir of the project where package.json resides.
npm install
Before starting the application make sure to check and modify the configuration within ./config/config.json
. This manual assumes that you have a live MongoDB to which this application can connect and you know the corresponding URI.
Start the application by typing in the project root (where index.js and package.json is):
node index.js
From now on the application is running and implements the following http endpoints:
- GET /records/:id This endpoint returns the single record that has the specified id. If the provided id does not exists it returnes with an ERROR message. If no id is given (GET /records) the application returns all the records.
- POST /records This endpoint inserts the object given in the body of the request (it is expected in JSON format). The JSON has to have an id member all other fields are optional. If the id already exists in the DB it returns with the following ERROR message:
ERROR! id: XX exists!
- DELETE /records/:id This endpoint deletes and returns the specified record. If the id is not available in the DB the application notifies the user in the reply.