Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What status code should a PATCH request with no changes return?

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?

like image 499
Andrei Prãdan Avatar asked Jul 12 '16 08:07

Andrei Prãdan


People also ask

What status code should PATCH return?

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.

Should I return a PATCH 204?

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.

Should Put return 200 or 204?

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.

Should POST return 200 or 201?

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.


2 Answers

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

like image 156
Yasss Avatar answered Oct 19 '22 22:10

Yasss


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

like image 32
lasec0203 Avatar answered Oct 19 '22 22:10

lasec0203