If a PATCH request is made with a VALID payload, but the values in the payload are exactly the same as those in db, should it return 200 or 400 or other status code?
Summary. The PATCH method could return a number of different status codes. For a successful PATCH, common status codes would likely be 200 (OK) or 204 (No Content). If the PATCH method was unsuccessful, status codes such as 304 (Not Modified), 400 (Bad Request), or 422 (Unprocessable Entity) may be seen.
204 No Content does not mean an error code. It still reflects a successful operation. This is from the MDN docs: The common use case is to return 204 as a result of a PUT request, updating a resource, without changing the current content of the page displayed to the user.
200 OK - This is the most appropriate code for most use-cases. 204 No Content - A proper code for updates that don't return data to the client, for example when just saving a currently edited document.
The POST method is used to send data to the server. Perhaps the most common status code returned is 200. It simply means that the request was received, understood, and is being processed, whereas the 201 status code indicates that a request was successful and a resource was created as a result. 1.
You have to return 4xx HTTP status code if there is an error.
In your case, there is not so I think that 200 is the best response.
The RFC says when you have to return an error status code.
https://www.rfc-editor.org/rfc/rfc5789#section-2.2
https://www.rfc-editor.org/rfc/rfc5789#section-2.1
you will return a 204 status code, which means "No Content" because you're not returning a body in the response
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With