RESTful optimistic locking in Restangular

444 views Asked by At

I have restful api where the client first loads a collection of entities from a resource

GET http://wherever/api/tasks

and then wants to delete a particular task from that collection

DELETE http://wherever/api/tasks/42

To protect against inadvertant deletion of concurrent updates, the delete should only succeed if the entity has not been modified since it has been loaded. We'd like to solve this using optimistic locking.

How do I pass the current / expected version through the REST API?

Apparently, the RESTful best practice is to pass the version through ETags (presumably to leverage synergies with HTTP caching), but how can I do this if the entity is loaded from a different URL than it will be deleted from? (I'd like to avoid issuing a GET for each individual task, as finding the collection of tasks is as expensive as finding their state)

We are using Restangular on the client side, and Jersey on the server side.

1

There are 1 answers

0
Brandon Brooks On

According to this issue your API must send the eTag as a property of the returned objects in collections and when you receive the response, attach it to the element's restangularEtag property.