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

12,748

Solution 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

Solution 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

Share:
12,748
Andrei Prãdan
Author by

Andrei Prãdan

python django enthusiast

Updated on June 30, 2022

Comments

  • Andrei Prãdan
    Andrei Prãdan almost 2 years

    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?

  • aalaap
    aalaap over 3 years
    204 is only when there is no content to return, but that does not have anything to do with whether the content on the server was modified or not. In the REST spec, you don't have to indicate the hit or miss via the HTTP status code.