Git Product home page Git Product logo

product-category-express's Introduction

Example REST service with Product and Category Backed by Express & mongo


The Task is Building a RESTful APIs from scratch using Express - Node.js.

  • The Entities are a “Categories” and “Products”.
  • Category can have multiple child categories.
  • Child category can have further child categories.
  • Category can have multiple products and product can have a multiple categories.
  • The Entities must get saved in MongoDb and be retrieved via POST and GET Methods respectively.

deepcode

Required

  • You need to design a proper Mongodb data model and create APIs to

  • Add a category

    Request

    POST http://localhost:3000/categories/
    Content-Type: application/json
    
    {
        "Name": "Category {{$randomInt 0 1000}}",
        "Description": "test category description",
        "ParentCategory": {
            "_id": "5f8881e0a0a9797f277597f8"
        }
    }
    
  • Add Product mapped to a category or categories.

    Request

    POST http://localhost:3000/products/
    Content-type: application/json
    
    {
        "Name": "X Product {{$randomInt 0 1000}}",
        "Brand": "xyz",
        "Sku": "123",
        "Price": 1200,
        "Categories": [
            {
                "Name": "test category {{$randomInt 0 1000}}",
                "Description": "this is test category"
            },
            {
                "Name": "test category 11 {{$randomInt 0 1000}}",
                "Description": "this is test category"
            }
        ]
    }
    
  • Get all categories with all its child categories mapped to it. Note : Each category object should look something like this {Id : 1 , child_categories: [], ...}

    Request

    GET http://localhost:3000/categories/
    
  • Get all products by a category.

    Request

    GET http://localhost:3000/products/?category[_id]=5f89299c4e29a3c1970bb9cf
    
  • Update product details (name,price,etc)

    Request

    PUT http://localhost:3000/products/5f892b6bfedb75cf01460ca3
    Content-Type: application/json
    
    {
        "Name": "X Product v {{$randomInt 0 1000}}",
        "Brand": "xyz",
        "Sku": "123",
        "Price": 1200,
        "Categories": [
            {
                "Name": "test category x {{$randomInt 0 1000}}",
                "Description": "this is test category"
            },
            {
                "Name": "test category x update {{$randomInt 0 1000}}",
                "Description": "this is test category"
            }
        ]
    }
    

Requests emulation

Use "REST Client" extension for VS Code to emulate request for development

"Request.rest" File has implemented requests for quick start

https://github.com/Huachao/vscode-restclient

Docker

  • docker-compose
    • docker-compose.yml file at root has development mongo instance listening on 27017
    • If using docker-compose you might need to stop local mongodb instance or change port

Development

  • Clone this repo

  • Install dependencies by

    npm install
  • Run service in development mode using nodemon watching for file changes

    npm run dev

product-category-express's People

Contributors

sunnyagain avatar

Watchers

 avatar  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.