The E-Commerce API provides a simple yet powerful backend solution for managing product inventory. Built with Node.js, Express.js, and MongoDB, it supports key operations like creating, updating, listing, and deleting products. The API is designed for scalability and ease of integration, with a clean, modular structure for future expansion. This project serves as a solid foundation for building more complex e-commerce systems.
- Demo: https://drive.google.com/file/d/1e29FwQJemFnSfZupkSPV2L7AtaWgeuX3/view?usp=sharing
- Hosted link: https://ecommerce-api-3-8uvj.onrender.com/products
This is an E-commerce API made using Node.Js & MongoDB.
STEPS TO USE THE API:
- run the "npm init" command on the terminal in this project directory
- start the server using node app.js
- Open postman
- Make a GET request on localhost:3000/products
- The products should be visible
STEPS TO CREATE A NEW PRODUCT:
- start the server using node app.js
- Open postman
- put localhost:3000/products/create as the URL.
- Select the Body tab below the URL textarea and then select x-www-form-URL-encoded
- Add name & quantity as the keys and set the desired values for the keys.
- Make a POST request.
- If you receive the message saying a new product added successfully then you have done everything correctly.
- The product is created. Check it out by making a GET request at localhost:3000/products
STEPS TO DELETE A PRODUCT:
- copy the object ID of the product you want to delete.
- add the id after localhost:3000/products/
- Make a DELETE request.
- You will receive a message saying deleted successfully.
STEPS TO UPDATE THE QUANTITY OF A PRODUCT:
- Copy the object ID of the product whose quantity you want to update
- Put the id after localhost:3000/products/
- After putting the id add /update_quantity/?number={x} in the URL where x is the number by which you want to increase or decrease the quantity.
- the URL should be looking like localhost:3000/products/{id}/update_quantity/?number={x}
- Make a POST request and you should get a message containing the updated product
- Node.js
- Express.js
- MongoDB
- Mongoose
- Create a Product
- URL: /products/create
- Method: POST
- Request Body: { "name": "laptop", "quantity": 10 }
- Response: { "data": { "product": { "name": "laptop", "quantity": 10 } } }
- List Products
- URL: /products
- Method: GET
- Response: { "data": { "products": [ { "id": "1", "name": "laptop", "quantity": 10 }, { "id": "2", "name": "camera", "quantity": 5 } ] } }
- Delete a Product
- URL: /products/:id
- Method: DELETE
- Response: { "data": { "message": "product deleted" } }
- Update Product Quantity
-
URL: /products/:id/update_quantity/?number=10
-
Method: POST
-
Response: { "data": { "product": { "id": "1", "name": "laptop", "quantity": 20 }, "message": "updated successfully" } }
e-commerce-api/ ├── models/ │ └── product.js # Mongoose schema for Product ├── controllers/ │ └── productsController.js # Contains all controller logic ├── routes/ │ └── products.js # Routes for product-related APIs ├── app.js # Entry point for the server ├── package.json # Project metadata and dependencies └── README.md # Documentation
This project is licensed under the MIT License.
SATYAM KUMAR