Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which HTTP status code to use to reject a PUT due to optimistic locking failure

Tags:

People also ask

What is the response code for put?

For a PUT request: HTTP 200, HTTP 204 should imply "resource updated successfully". HTTP 201 if the PUT request created a new resource. For a DELETE request: HTTP 200 or HTTP 204 should imply "resource deleted successfully".

What is the HTTP status codes for not implemented?

Error 501 is a HyperText Transfer Protocol (HTTP) status code that stands for Not Implemented. This server error response code means that your web server does not support the functionality required for access and does not recognize the request method.


Assume I'd like to implement some kind of optimistic locking and use ETags to indicate the most up to date resource state. This means, clients will use an If-Match header when PUTting for an update.

According to the HTTP spec, the server has to return 412 Precondition failed if the ETag provided for the If-Match header doesn't match the current state of the resource.

However, 409 Conflict seems to be closer to what I want to express semantically, especially as it gives guidelines what to include in the response.

Is it terribly wrong to rather return 409 in case of a failure to match an ETag provided in an If-Match header?