/getir-case-study

Getir Case Study

Primary LanguageJavaScript

Getir Case Study

A RESTful API generated by generator-rest.

See the API's documentation or GitHub Pages.

Commands

After you generate your project, these commands are available in package.json.

npm test # test using Jest
npm run coverage # test and open the coverage report in the browser
npm run lint # lint using ESLint
npm run dev # run the API in development mode
npm run prod # run the API in production mode
npm run docs # generate API docs

Playing locally

Only, you will need to specify the value of MONGODB_URI variable in .env file


API Examples

Getting first 100 records:

curl -X GET \
  http://localhost:9000/records \
  -H 'cache-control: no-cache'

It will return something like:

HTTP/1.1 200 OK
...
{
  "code": 0,
  "msg": "Success",
  "records": [
    {
      "id": "58adc57a1f84e37c19df0cc6",
      "key": "YhwZESHNaSY2gZoi",
      "createdAt": "2016-11-18T08:49:23.108Z",
      "counts": [
        600,
        0
      ]
    },
    {
      "id": "58adc57a1f84e37c19df0ccb",
      "key": "8oDJX4FosoHgkUUz",
      "createdAt": "2017-02-07T13:23:38.320Z",
      "counts": [
        600,
        100,
        400,
        500,
        700,
        200,
        300
      ]
    },
    ...
  ]
}

- Querying of records:

curl -X POST \
  http://localhost:9000/records \
  -H 'Content-Type: application/json' \
  -H 'cache-control: no-cache' \
  -d '{
	"startDate": "2017-01-26",
	"endDate": "2017-01-28",
	"minCount": 2700,
	"maxCount": 3000
}'

It will return something like:

HTTP/1.1 200 OK
...
{
  "code": 0,
  "msg": "Success",
  "records": [
    {
      "key": "SqAICaG0XNS2beZ6",
      "createdAt": "2017-01-27T01:38:19.181Z",
      "totalCount": 2800
    },
    {
      "key": "fDqbRGWdthiUwUcd",
      "createdAt": "2017-01-27T02:00:32.139Z",
      "totalCount": 2900
    },
    ...
  ]
}

Directory structure

src/api/

Here is where the API endpoints are defined. Each API has its own folder.

src/api/record/model.js

It defines the Mongoose schema and model for the Records API endpoint. Any changes to the data model should be done here.

src/api/record/controller.js

This is the Records API controller file. It defines the main router middlewares which use the API model.

src/api/record/index.js

This is the entry file of the Records API.

services/

Here you can find helpers, libraries and other types of modules which I use in my APIs.