Giter Site home page Giter Site logo

fuzzy-spoon's Introduction

fuzzy-spoon

API with a single endpoint that fetches the data from the MongoDB collection and return the results in the requested format

Requirements

  • nodejs version >= 14
  • npm version >= 7
  • mongoDB

Install and run

  • npm i - install dependencies
  • set environment variables PORT and MONGODB_CONNECTION_URL
  • npm start - run the server

To run the tests:

  • npm test

API

After server is started you can send a POST request it.

Request Payload

The request payload will include a JSON with 4 fields:

  • startDate and endDate fields will contain the date in a YYYY-MM-DD format. They are used to filter the data using createdAt property.
  • minCount and maxCount are for filtering the data. Sum of the count array in the documents should be between minCount and maxCount.

Sample:

{
    "startDate": "2016-01-26", 
    "endDate": "2018-02-02", 
    "minCount": 2700, 
    "maxCount": 3000
}

Response Payload

Response payload has 3 main fields:

  • code is for status of the request. 0 means success. See more details about error codes below
  • msg is for description of the code. It contains "success" for successful requests. For unsuccessful requests it provides explanatory messages.
  • records will include all the filtered items according to the request. This array should include items of key, createdAt and totalCount which is the sum of the counts array in the document.

Sample:

{
  "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
    } 
  ]
}
Error response examples
  • {"code": 1, "msg": "system error"} - general system error, all unexpected error will have this response
  • {"code": 2, "msg": "request.body.minCount should be number"} - request payload validation error, msg will contain the details. Check you send request payload using expected format
  • {"code": 3, "msg": "startDate should be less than endDate"} - error with startDate / endDate
  • {"code": 4, "msg": "minCount should be less that maxCount"} - error with minCount / maxCount

fuzzy-spoon's People

Contributors

s0ph1e avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.