Optimistic Concurrency
WARNING
This API is frozen and deprecated. Please use the fluent API from 0.9.4 on
When sending requests that are intended to change an existing resource (PUT
, PATCH
, DELETE
) there is a chance someone else has made a change between your GET
request the request with your intended changes. Halchemy relies on optimistic concurrency to handle this possibility. That is, it assumes no one else has made a change, but populates the If-Match
header with the resource's ETag so the server can reject the request if a change to the resource has taken place - that is if the ETag of the resource on the server doesn't match the requested change.
For your client to handle this, you must handle exceptions thrown by the request. If the status code is 412 that means someone else has sneaked in a change. What the client does is up to you. For example, you could:
- show the user the updated version, let them merge their change into it then resubmit the request
- cancel the operation, advise the user they should refresh and start over
- GET the updated resource, automatically merge the changes - or even overwrite them with the version you are trying to submit
- etc.
Here is an example that advises the user to refresh and try again.