Giter Club home page Giter Club logo

shopping-restapi's Introduction

Shopping API

Description

  • Built a REST API in Node.js using the MVC approach by leveraging Node.js + MongoDB.
  • User JWT for Authentication and Authorization.
  • A RESTful API built for serving as a Backend for a Shopping Cart.

Requirements

For development, you will only need Node.js and a node global package, Yarn, installed in your environement.

Node

  • Node installation on Windows

    Just go on official Node.js website and download the installer. Also, be sure to have git available in your PATH, npm might need it (You can find git here).

  • Node installation on Ubuntu

    You can install nodejs and npm easily with apt install, just run the following commands.

    $ sudo apt install nodejs
    $ sudo apt install npm
    
  • Other Operating Systems

    You can find more information about the installation on the official Node.js website and the official NPM website.

If the installation was successful, you should be able to run the following command.

$ node --version
v8.11.3

$ npm --version
6.1.0

If you need to update npm, you can make it using npm! Cool right? After running the following command, just open again the command line and be happy.

$ npm install npm -g

Install

$ git clone https://github.com/vinod2305/Shopping-RESTapi.git
$ cd Shopping-RESTapi
$ npm install

Running the project

$ npm start

Shopping Api

Indices


User

1. POST - signup

Endpoint:

Method: POST
Type: RAW
URL: http://localhost:3000/user/signup

Body:

{
    "email":"[email protected]",
    "password": "password"
}
I. Example Response: POST - signup
{
    "message": "User created"
}

Status Code: 201

2. POST - login

Endpoint:

Method: POST
Type: RAW
URL: http://localhost:3000/user/login

Body:

{
    "email":"[email protected]",
    "password": "password"
}
I. Example Response: POST - login
{
    "message": "Auth successful",
    "token": {token}
}

Status Code: 201

3. DELETE - delete user

Endpoint:

Method: DELETE
Type: 
URL: http://localhost:3000/user/60ddabe0d864375a684dc930
I. Example Response: DELETE - delete user
{
    "message": "User deleted"
}

Status Code: 200

Product

1. GET - get all products

Endpoint:

Method: GET
Type: 
URL: http://localhost:3000/products
I. Example Response: GET - get all products
{
    "count": 1,
    "products": [
        {
            "name": "Test product",
            "price": 100,
            "_id": "60ddb145d864375a684dc933",
            "productImage": "uploads/2021-07-01T12:12:53.719Ztestproduct.jpeg",
            "request": {
                "type": "GET",
                "url": "http://localhost:3000/products/60ddb145d864375a684dc933"
            }
        }
    ]
}

Status Code: 200

2. GET - get product

Endpoint:

Method: GET
Type: 
URL: http://localhost:3000/products/60ddb145d864375a684dc933
I. Example Response: GET - get product
{
    "product": {
        "_id": "60ddb145d864375a684dc933",
        "name": "Test product",
        "price": 100,
        "productImage": "uploads/2021-07-01T12:12:53.719Ztestproduct.jpeg"
    },
    "request": {
        "type": "GET",
        "description": "GET ALL PRODUCTS",
        "url": "http://localhost/product"
    }
}

Status Code: 200

3. POST - create product

Endpoint:

Method: POST
Type: FORMDATA
URL: http://localhost:3000/products

Body:

Key Value Description
name Test product Name of the product
price 100 Price of product
productImage File
More example Requests/Responses:
I. Example Response: POST - create product
{
    "message": "Created product successfully",
    "createdProduct": {
        "name": "Test product",
        "price": 100,
        "_id": "60de8d65024f812237aec95e",
        "productImage": "uploads/2021-07-02T03:52:05.675Ztestproduct.jpeg",
        "request": {
            "type": "GET",
            "url": "http://localhost:3000/products/60de8d65024f812237aec95e"
        }
    }
}

Status Code: 201

4. UPDATE - update product

Endpoint:

Method: PATCH
Type: RAW
URL: http://localhost:3000/products/60ddb145d864375a684dc933

Body:

[
    {
        "price": "150"
    }
]
I. Example Response: UPDATE - update product
{
    "message": "Product updated",
    "request": {
        "type": "GET",
        "url": "http://localhost/product/60ddb145d864375a684dc933"
    }
}

Status Code: 200

5. DELETE - delete product

Endpoint:

Method: DELETE
Type: 
URL: http://localhost:3000/products/60ddb145d864375a684dc933
I. Example Response: DELETE - delete product
{
    "message": "Product Deleted",
    "request": {
        "type": "POST",
        "url": "http://localhost:3000/products",
        "body": {
            "name": "String",
            "price": "Number"
        }
    }
}

Status Code: 200

Order

1. GET - get all orders

Endpoint:

Method: GET
Type: 
URL: http://localhost:3000/orders
I. Example Response: GET - get all orders
{
    "count": 1,
    "orders": [
        {
            "_id": "60ddb47ad864375a684dc936",
            "product": {
                "_id": "60ddb395d864375a684dc934",
                "name": "Test product"
            },
            "quantity": 20,
            "request": {
                "type": "GET",
                "url": "http://localhost:3000/orders/60ddb47ad864375a684dc936"
            }
        }
    ]
}

Status Code: 200

2. GET - get order

Endpoint:

Method: GET
Type: 
URL: http://localhost:3000/orders/60ddb47ad864375a684dc936
I. Example Response: GET - get order
{
    "order": {
        "quantity": 20,
        "_id": "60ddb47ad864375a684dc936",
        "product": {
            "_id": "60ddb395d864375a684dc934",
            "name": "Test product",
            "price": 100,
            "productImage": "uploads/2021-07-01T12:22:45.184Ztestproduct.jpeg",
            "__v": 0
        },
        "__v": 0
    },
    "request": {
        "type": "GET",
        "url": "http://localhost:3000/orders"
    }
}

Status Code: 200

3. POST - create order

Endpoint:

Method: POST
Type: RAW
URL: http://localhost:3000/orders

Body:

{
    "productId": "60ddb395d864375a684dc934",
    "quantity": "20"
}
I. Example Response: POST - create order
{
    "message": "Order stored",
    "createdOrder": {
        "_id": "60ddb42bd864375a684dc935",
        "product": "60ddb395d864375a684dc934",
        "quantity": 20
    },
    "request": {
        "type": "GET",
        "url": "http://localhost:3000/orders/60ddb42bd864375a684dc935"
    }
}

Status Code: 201

4. DELETE - delete order

Endpoint:

Method: DELETE
Type: 
URL: http://localhost:3000/orders/60ddb47ad864375a684dc936
I. Example Response: DELETE - delete order
{
    "message": "Order deleted",
    "request": {
        "type": "POST",
        "url": "http://localhost:3000/orders",
        "body": {
            "productId": "ID",
            "quantity": "Number"
        }
    }
}

Status Code: 200


Back to top

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.