Save new product in database.
URL: /api/products
Method: POST
{
"name": "[string (4-100 characters range)]",
"price": "[integer]"
}
{
"name": "jacket",
"price": 200
}
Code: 200 OK
Condition: If provided data is correct.
{
"__v": 0,
"_id": "6369523318c90dd1e14fd8b0",
"createdAt": "2022-11-07T18:45:07.229Z",
"name": "jacket",
"price": 200,
"updatedAt": "2022-11-07T18:45:07.229Z"
},
Code: 400 BAD REQUEST
Condition: If no name provided.
{ "name": "Please provide the product name" }
Code: 400 BAD REQUEST
Condition: If provided name is shorter than 4 chars.
{ "name": "Product name is too short. Minimum length is 4 characters" }
Code: 400 BAD REQUEST
Condition: If provided name is longer than 100 chars.
{ "name": "Product name is too long. Maximum length is 100 characters" }
Code: 400 BAD REQUEST
Condition: If no price provided.
{ "price": "Please provide the product price" }
Code: 400 BAD REQUEST
Condition: If provided price is not integer type.
{ "price": "Provided price has to be a numeric value" }