Skip to content

Latest commit

 

History

History
92 lines (61 loc) · 1.32 KB

post.md

File metadata and controls

92 lines (61 loc) · 1.32 KB

Create transaction

Description

Save new product in database.

URL: /api/products

Method: POST

Data constraints

{
  "name": "[string (4-100 characters range)]",
  "price": "[integer]"
}

Data example

{
  "name": "jacket",
  "price": 200
}

Success Response

Code: 200 OK

Condition: If provided data is correct.

Context example

{
    "__v": 0,
    "_id": "6369523318c90dd1e14fd8b0",
    "createdAt": "2022-11-07T18:45:07.229Z",
    "name": "jacket",
    "price": 200,
    "updatedAt": "2022-11-07T18:45:07.229Z"
  },

Error Response

Name

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" }

Price

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" }