As you wrote, there’s regularly some debate. That’s why it’s also useful to have an authoritative source of truth to confirm what a server should do if we want to make it follow the standards.
And that’s where RFC 7231 (section 4.3.4) comes in to confirm what you wrote:
If the target resource does not have a current representation and the PUT successfully creates one, then the origin server MUST inform the user agent by sending a 201 (Created) response.
If the target resource does have a current representation and that representation is successfully modified in accordance with the state of the enclosed representation, then the origin server MUST send either a 200 (OK) or a 204 (No Content) response to indicate successful completion of the request.
Every time such discussion starts in a design doc review or code review, following RFC is very helpful. We need very strong reason and special edge cases to pick non standard behaviors.
In case of successful PUT, 201 is ought to be used right?
Hey, thank you for pointing that out!
Yes, you are right!
200 - when a resource is successfully updated and sends a response.
201 - when a resource is successfully created. (This can be done by POST also)
204 - when a resource is successfully updated but sends no response
Sébastien Portebois
As you wrote, there’s regularly some debate. That’s why it’s also useful to have an authoritative source of truth to confirm what a server should do if we want to make it follow the standards.
And that’s where RFC 7231 (section 4.3.4) comes in to confirm what you wrote:
src: tools.ietf.org/html/rfc7231
Every time such discussion starts in a design doc review or code review, following RFC is very helpful. We need very strong reason and special edge cases to pick non standard behaviors.