Upsert in a RESTFUL API - What I would have done differently
What would I have done differently facing the upsert situation ?
Some relevant quotes from the RFC 7231:
The
PUT
method requests that the state of the target resource be created or replaced with the state defined by the representation enclosed in the request message payload. [...]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 a201
(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 a200
(OK) or a204
(No Content) response to indicate successful completion of the request. [...]
The
200
(OK) status code indicates that the request has succeeded. The payload sent in a200
response depends on the request method. For the methods defined by this specification, the intended meaning of the payload can be summarized as:[...]
PUT
,DELETE
: a representation of the status of the action;[...]
The
201
(Created) status code indicates that the request has been fulfilled and has resulted in one or more new resources being created. The primary resource created by the request is identified by either aLocation
header field in the response or, if noLocation
field is received, by the effective request URI. [...]
The
204
(No Content) status code indicates that the server has successfully fulfilled the request and that there is no additional content to send in the response payload body. Metadata in the response header fields refer to the target resource and its selected representation after the requested action was applied. [...]
Comments