Simple API to do CRUD operations on products and carts.
List all products
- URL:
/api/products
- Method:
GET
- Response:
200 (OK)
JSON with products array.
{
"products": [
{
"id": "1652273047326",
"timestamp": "2022-05-11T12:44:07.326Z",
"name": "random product",
"description": "description for a random product",
"stock": 5,
"price": 150,
"code": "coder30940",
"photo": ""
}
]
}
Add new product
- URL:
/api/products
- Method:
POST
- Response:
201 (Created)
- Error:
400 (Bad request)
Field | Type |
---|---|
name | string |
description | string |
photo | string |
code | string |
stock | number |
price | number |
JSON with added product
{
"added": {
"id": "1652273047326",
"timestamp": "2022-05-11T12:44:07.326Z",
"name": "random product",
"description": "description for a random product",
"stock": 5,
"price": 150,
"code": "coder30940",
"photo": ""
}
}
Update a product
- URL:
/api/products/{product_id}
- Method:
PUT
- Response:
204 (No content)
- Error:
404 (Not found)
Field | Type |
---|---|
name | string |
description | string |
photo | string |
code | string |
stock | number |
price | number |
Remove a product
- URL:
/api/products/{product_id}
- Method:
DELETE
- Response:
204 (No content)
- Error:
404 (Not found)
Create a new cart
- URL:
/api/cart/
- Method:
POST
- Response:
201 (Created)
JSON with cart ID
{
"cart": "1652273568738"
}
Remove a cart
- URL:
/api/cart/{cart_id}
- Method:
DELETE
- Response:
204 (No content)
- Error:
404 (Not Found)
List all products from cart
- URL:
/api/cart/{cart_id}/products
- Method:
GET
- Response:
200 (OK)
- Error:
404 (Not Found)
JSON with products array
{
"products": [
{
"id": "1652273047326",
"timestamp": "2022-05-11T12:44:07.326Z",
"name": "random product",
"description": "description for a random product",
"stock": 5,
"price": 150,
"code": "coder30940",
"photo": ""
}
]
}
Add a new product into cart
- URL:
/api/cart/{cart_id}/products/{product_id}
- Method:
POST
- Response:
204 (No content)
- Error:
404 (Not Found)
Remove a product from cart
- URL:
/api/cart/{cart_id}/products/{product_id}
- Method:
DELETE
- Response:
204 (No content)
- Error:
404 (Not Found)