Skip to content

DataWorker2001/E-COMMERCE-API

Repository files navigation

Ecommerce Inventory Management API

Contributed By: Arpan Choudhury

image

This project implements an API for an ecommerce platform admin to manage product inventory using Node.js and MongoDB. It provides endpoints to add, list, update, and delete products from the inventory.

Tech Stack:- Node.js and MongoDB

Folder Structure:-
ecommerce-api
├── models
│ └── product.js
├── controllers
│ └── productController.js
├── routes
│ └── productRoutes.js
├── config
│ └── db.js
├── server.js
└── package.json
└── package-lock.json
└── README.md
└── .gitattributes
└── .gitignore
└── Test 1 - Ecommerce API.docx

Setup:- To set up the project on your local system, follow these steps:

  1. Clone the repository:-
    $ Shell/Terminal:
    git clone https://github.com/DataWorker2001/E-COMMERCE-API.git

  2. Install dependencies:-
    $ Shell/Terminal:
    cd ecommerce-api
    npm install

  3. Configure the MongoDB connection in db.js using the dbURI variable as:
    const dbURI = 'mongodb+srv://:@cluster0.hciafyn.mongodb.net/ecom';
    after creating a db.js file in the config folder in the root directory and the rest code.

  4. Start the server:
    $ Shell/Terminal
    npm start
    The server will start running on http://localhost:3000.
    ---------------------------------------------------------------------------x-----------------------------------------------------------------------------

API Endpoints:-

i) Add a product to the database URL [POST]: /products/create

Request body:

$json:
{ "name": "laptop", "quantity": 10 } Response body:

$json:
{ "product": { "name": "laptop", "quantity": 10 } }

ii) List all products URL [GET]: /products

Response body:

$json

{ "products": [ { "id": 1, "name": "laptop", "quantity": 10 }, { "id": 2, "name": "camera", "quantity": 5 }, { "id": 3, "name": "smartwatch", "quantity": 8 } ] } iii) Delete a product URL [DELETE]: /products/:id

Response body:

$json:
{ "message": "product deleted" }

iv) Update quantity of a product URL [POST]: /products/:id/update_quantity/?number=10

Response body:

$json:
{ "product": { "id": 1, "name": "laptop", "quantity": 20 }, "message": "updated successfully" }

This README provides an overview of the project, setup instructions, and details about the available API endpoints.

Good luck with this project! If you find any problems in the code, feel free to start the forking of this repo. and using pull requests.