Implementing an endpoint to update a note using HTTP verb PUT
To update Note, we will implement the endpoint that meets specific requirements. Let's make a list of these requirements for our update 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
PUT. - The HTTP route will be
/notes/:id. - The request body will have a payload representing a
Notein JSON format.
The response is expected to meet the following criteria:
- When a malformed JSON is present in the request payload, the following will occur:
- The response body will have a
CustomResponsestruct encoded into JSON with a reasonable message. - The status code will show
400, Bad Request.
- The response body will have a
- If the proper JSON payload of the
Noteis present in the request body, do the following:- Check whether the
Noteto be updated exists in the database using the built-inorm-based syntax.
- Check whether the
- When a
Note...