Sean Landis wrote:
Adam Taft <adam <at> adamtaft.com> writes:
[... deleted ...]
I'm assuming you're using a web browser client, because an "adjustment"
to an existing resource would imply PUT, right? But, as we know,
PUT/DELETE sucks on web browsers.
The operation is not idempotent so it cannot be PUT.
Right right, I missed that. Sorry. You're doing relative inventory
adjustments, not discreet.
I guess having given this some thought before, I think of it as discreet
PUTs to avoid the race condition.
You GET an inventory resource or quantity-on-hand resource, and then
your client makes an adjustment to the quantity and you PUT the resource
back. But, if another client (or operation) has come along and also
updated the quantity, you'll get a 409 Conflict based on the Etag
conditional. This allows the original client to re-request the actual
quantity and try the transaction again, or abort because there is now
not enough inventory.
Otherwise, you might get two clients at the same time thinking they have
enough quantity to safely POST to your adjustment URL and end up with
negative on-hand inventory.
Maybe you just error out at that point, so it's no big deal regardless.
Obviously I don't know your application, so I'll shush now. :)
Adam