- Clone the Project in local PC
- install dependencies
npm install
- Add Database URL
- You can add it to .env file (1st Preference)
- You can add it to app.js file.
- Run development server
npm run dev
I have developed Homepage where you can see working of all api end points.
Just Open endpoint "/"
If you are running development server from localhost then open localhost:8000
GET /product
List of Product information
Definitions
_id : Product Id product_name : Product Name product_image" : Product Image description : Product Description quantity : Stock Available unit_price : Price of single product
Sample
[
{
"_id": "62c8795e49b15ab1506d64b0",
"product_name": "Pencil",
"product_image": "Pencil_1657305438191.jpg",
"description": "Very Great Pencil",
"quantity": 7,
"unit_price": 15,
"__v": 0
},
{
"_id": "62c91503cffddea81137e42b",
"product_name": "Pencil 2",
"product_image": "Pencil 2_1657345282598.jpg",
"description": "not good",
"quantity": 10,
"unit_price": 55,
"__v": 0
}
]
POST /product
content type : multipart/form-data
Parameters
product_name : Product Name : String : Required description : Product Description : String : quantity : Stock Available : Int : Required unit_price : Price of single product : Int : Required product_image : Product Image : Image :
Definitions
"msg" : Status "item" : New Product
Sample
{
"msg" : "Product Added",
"item" : {
"product_name" : "Product Name",
"product_image" : "product image name.jpg",
"description" : "product description",
"quantity" : 57,
"unit_price" : 18,
"_id" : "62c9217b2bbc237530f357c8",
"__v" : 0
}
}
GET /cart
List of Cart items and total amount
Definitions
cart : List Of cart Items totalAmount : total Cart Amount
Cart Item Definitions
product_id : Json object containing product information quantity : Units of that product items added in cart
More about product information can be found in List product Endpoint
Sample
{
"cart":[
{
"_id":"62c916b200304c377631761e",
"product_id":{
"_id":"62c8795e49b15ab1506d64b0",
"product_name":"Pencil",
"product_image":"Pencil_1657305438191.jpg",
"description":"Very Great Pencil",
"quantity":7,
"unit_price":15,
"__v":0
},
"quantity":4,
"__v":0
}
],
"totalAmount":60
}
POST /cart
content type : json
Parameters
product_id : Product ID : String : Required
Definitions
"msg" : Status "item" : Item added to cart
Different Status Messages
- Added to Cart
- Product does not exist
- Already in Cart
Sample
{
"msg" : "Added to Cart",
"item" : {
"product_id" : "62c879bb0a3c22b963129bcd",
"quantity" : 1,
}
}
POST /cart/update
content type : json
Parameters
product_id : Product ID : String : Required action : increase/decrease : String : Required
Definitions
"msg" : Status "item" : Updated Cart Item
Different Status Messages
- Cart updated
- We do not have enough stock to add one more item
- Item Deleted
Sample
{
"msg" : "Cart updated",
"item" : {
"product_id" : "62c879bb0a3c22b963129bcd",
"quantity" : 2
}
}
