What design patterns are best for checkin / checkout / abort in a REST interface?
Jonathan--
You received this message because you are subscribed to the Google Groups "API Craft" group.
To unsubscribe from this group, send email to api-craft+...@googlegroups.com.
Visit this group at http://groups.google.com/group/api-craft?hl=en.
On Nov 7, 2012 4:37 PM, "Jonathan Robie" <jonathan.robie@ibiblio.org> wrote:
>
> We definitely need optimistic locking, but we need
> pessimistic locking as well, including long term
> pessimistic locking where someone checks
> something out for hours or days.
>
> Setting properties isn't quite what I'm looking for;
Would updating (via put) a "reserved_by" property of the resource using an etag based optimistic lock solve the problem? The server could then reject any modification requests from other users. This would seem to allow basic checkout/in/abort. If these checkouts are multi-resource you'll need some way to deal with deadlocks but it seems like that would be the case regardless.
Peter
Barelyenough.org
--
I won't call it right or wrong, but having an "action" parameter is probably not what most API developers would consider RESTful, as there already is an action provided by the HTTP method.
Is it very important that the checkout and read object are an atomic operation? As soon as the object is locked, will atomicity be of great significance?My suggestion is to introduce a sub-resource on the object that can be checked out or, in my words, locked? Assuming the resources are "books" and the subresource is "lock":GET /books/42/lock -> 404 Not Found = not locked by anyoneGET /books/42/lock -> 200 OK = locked by someonePUT /books/42/lock -> 403 Forbidden = already locked by someone elsePUT /books/42/lock -> 200 OK = you locked it now (or refreshed an existing lock)DELETE /books/42/lock -> 403 Forbidden = you are not allowed to unlock itDELETE /books/42/lock -> 200 OK = you unlocked itGET /books/42 -> 403 Forbidden = not lockedGET /books/42 -> 200 OK = locked by you so you can read itPUT /books/42 -> 403 Forbidden = not lockedPUT /books/42 -> 200 OK = locked by you so you can replace itDELETE /books/42 -> 403 Forbidden = not lockedDELETE /books/42 -> 200 OK = locked by you so you can delete it
--