[Catalyst] Dispatching with Chained vs HTTP method
adam.clarke at strategicdata.com.au
Wed May 7 06:30:12 BST 2008
On 07/05/2008, at 11:05 AM, Toby Corkindale wrote:
> Ah, I was thinking of transactions vs a REST API, eg:
> PUT /user/1234/account_balance?subtract=1
> POST /user/4567/account_balance?add=1
> Since those are two separate HTTP requests, and REST specifically
> states you
> cannot maintain state on the server, how would you perform those two
> operations inside a transaction?
> (My "solution" is to implement it in one request, like:
> PUT /user/1234/money_transfer?user=4567;amount=1
> However that is not CRUD-like, nor a direct mapping of DBIC
> functionality to
The solution suggested in "Restful Web Services" is to POST to a
"factory" resource which creates you with a transaction resource. e.g.
"POST /transactions/account-transfer" returns "Location: /
transactions/account-transfer/11a5", where the 11a5 is a unique
Then "PUT /transactions/account-transfer/11a5/accounts/checking/11",
where 11 is the account identifier. The body carries the transaction
details, in the example the balances are adjusted absolutely, i.e.
"balance=150". A similar PUT is sent for the other account.
Once the required components of the transaction have been PUT it is
possible to rollback by DELETEing the transaction resource or commit
it by putting "committed=true" to the resource.
While seeming a bit fiddly, it does keep the state on the client and
allows the client to make (at least some of) the commit / rollback
decision rather than (only) the server.
More information about the Catalyst