https://can-yolal-getir-task.herokuapp.com/filterdata
This Node.js program handles HTTP post request for a single endpoint named "/filterdata". This API does a simple filtering operation on a data from MongoDB collection and returns a response with matching results.
gh repo clone getir-nodejs-bootcamp/getir-nodejs-bootcamp-graduation-project-canyolal
cd getir-nodejs-bootcamp-graduation-project-canyolal
Download libraries with npm install
first.
Then, create .env file on project folder to set MongoDB instance.
Start server with npm start
Execute tests with npm test
To execute single test npm test -- -t "specific test name"
npm run dev
to execute development mode.
Sample request:
curl -X POST https://can-yolal-getir-task.herokuapp.com/filterdata -H 'Content-Type: application/json' -d '{"startDate": "2015-01-15","endDate": "2015-01-21","minCount": 0,"maxCount": 55}'
The request payload will include a JSON with 4 fields.
- “startDate” and “endDate” fields will contain the date in a “YYYY-MM-DD” format.(Type: String)
- “minCount” and “maxCount” are for filtering the data.(Type: Number)
Sample Input:
{
"startDate": "2016-01-26",
"endDate": "2018-02-02",
"minCount": 2700,
"maxCount": 3000
}
Response payload have 3 main fields and returns JSON.
- “code” is for status of the request.(Type: Number)
- “msg” is for description of the code.(Type: String)
- “records” will include all the filtered items according to the request.(Type: Array)
{
"code":0,
"msg":"Success",
"records":[
{
"key":"TAKwGc6Jr4i8Z487",
"createdAt":"2017-01-28T01:22:14.398Z",
"totalCount":2800
},
{
"key":"NAeQ8eX7e5TEg7oH",
"createdAt":"2017-01-27T08:19:14.135Z",
"totalCount":2900
}
]
}
Response codes are listed below:
- code:0, msg: 'success', records: [obj] indicates that server found a matching doc(s)
- code:0, msg: 'no match', records: [] indicates that server did not find any matching doc
- code:500, msg: 'error while processing', records: [] indicates that server encounter a problem while filtering docs
- code:501, msg: 'error fetching from db', records: [] indicates that server encounter a problem while fetching docs
- code:400, msg: 'dynamic response w.r.t. error', records: [] indicates that user entered an invalid value for payload keys
- code:400, msg: 'missing payload', records: [] indicates that payload not found or payload not in JSON format
- code:404, msg: 'invalid url', records: [] indicates that user sent a request to invalid endpoint
- Express: server management
- mongoose: mongodb connection
- jest: testing
- supertest: testing
- dotenv: environment parameters
- joi: payload validator
- heroku: deployment