Implementing an endpoint to create a note using HTTP verb POST
To create a record of Note in the database, we will implement the endpoint that meets specific requirements. Let's make a list of the requirements for our create endpoint to gain an understanding of what the request and response should look like.
The request is expected to meet the following criteria:
- The HTTP method will be
POST. - The HTTP route will be
/notes/. - The request body will have a payload representing
Notein JSON format.
The response is expected to meet the following criteria:
- When a malformed JSON is present in the request payload, or when a message is not unique, we expect the following to occur:
- The response body will have a
CustomResponsestruct encoded into JSON format whosemessageandstatusfield are set accordingly. - The status code will show
400, Bad Request.
- The response body will have a
- If the proper JSON payload of
Noteis present in the request body, respond with the following:- Insert the...