/jsonapi

REST-based JSON mock server for CRUD operation from a JSON file

Primary LanguageJavaScript

CommerceIQ: SDE-Intern: Home Assignment

Problem Statement:

  • Build a REST based JSON mock server to easily add, update, delete and access data from a JSON file.

    • Every data set should have a parent identifier (entity type), which will be used in the GET APIs.

    • Every data set should have an ID (Primary key)

    • ID should be immutable, error needs to be thrown if ID is tried to be mutated.

    • If you make POST, PUT, PATCH or DELETE requests, changes have to be automatically saved to store.json.

    • The store.json file should support multiple entity types.

      Schema_Look

  • Sample APIs to be supported by the mock server on store.json file:

    • GET /posts
    • GET /posts/0
    • POST /posts
    • PUT /authors/1
    • PATCH /posts/1
    • DELETE /posts/1
  • Enable filtering at entity level :

    • GET /posts?title=title1&author=CIQ
  • Enable sorting at entity level :

    • GET /posts?_sort=views&_order=asc
  • Enable basic search at entity level:

    • GET /posts?q=IQ
  • Support for nested structures will yield a bonus point.

  • Treat store.json as an empty slate where you can add and retrieve any data.


Solution:

  • Language Used - JavaScript (NodeJS)

Implemented all the below features according to problem statement and code hosted on GitHub along with CI-CD pipeline (GitHub Actions) and APIs hosted on AWS EC2 instance for user consumption.

Features:-

  • Every data set should have a parent identifier (entity type), which will be used in the GET APIs.

  • Every data set should have an ID (Primary key)

  • ID should be immutable, error needs to be thrown if ID is tried to be mutated.

  • If you make POST, PUT, PATCH or DELETE requests, changes have to be automatically saved to store.json.

  • The store.json file should support multiple entity types.

  • Sample APIs to be supported by the mock server on store.json file:

    GET /posts
    GET /posts/0
    POST /posts
    PUT /authors/1
    PATCH /posts/1
    DELETE /posts/1
  • Enable filtering at entity level :

    • GET /posts?title=title1&author=CIQ
  • Enable sorting at entity level :

    • GET /posts?_sort=views&_order=asc
  • Enable basic search at entity level:

    • GET /posts?q=IQ
  • Support for nested structures will yield a bonus point.

  • Treat store.json as an empty slate where you can add and retrieve any data.

API Documentation:-

Data Store:-

Code Repository:-

├── config
│   └── config.js
├── dbutils
│   ├── controllers.js
│   ├── routes.js
│   └── service.js
├── package.json
├── package-lock.json
├── postman_collection.json
├── README.md
├── server.js
└── store.json
  • Entry point file - server.js
  • packages dependencies -
{
  "dependencies": {
    "async-mutex": "^0.2.6",
    "cors": "^2.8.5",
    "express": "^4.17.1",
    "express-validator": "^6.9.0",
    "morgan": "^1.10.0",
    "underscore": "^1.12.0"
  },
  "devDependencies": {
    "nodemon": "^2.0.6"
  }
}

Special Features Implemented:-

  • Infinite Nesting (Level of Threading can be go upto any level, something like reddit discussion threads)
  • Used Mutex locks for simultaneous writes