> Thanks John for the great feedback. 
> 
> > On the source account, you'd initiate a transfer with the arguments 
> > being the target account and the amount.  The result on 
> success would 
> > be that specific transfer's ID.
> 
> Ah, but you're not saying how you 'initiate a transfer'. It's 
> one of the questions I'm struggling with. It  could be:
> ...
> POST /transfer/account/123
> Host: myserver.com
> Content-Length: XXX
>    <toAccount>456</toAccount>
>    <amount>300</amount> 
> 
> The problem I  have with the first approach is that I'm still 
> passing an action, i.e. doing some kind of RPC. My 
> understanding is that in a 'pure' RESTful API the only way to 
> specify the action is via the HTTP method (get,post,put,delete).
>  The second solution seems even worse as it mixes the action 
> with the resource.

It *seems* like you're passing an action, but IMO what you're actually
doing is turning the action into a resource, which is very powerful.
That resource has a unique address, a state that can be transferred, and
is only manipulated with our four magic verbs. You can even make it
asynchronous by posting a transaction and polling for its status later
at the resource's URL.

There was actually a useful post about this sort of approach on
rest-discuss a couple days ago:

http://tech.groups.yahoo.com/group/rest-discuss/message/6561
 
> And what if I want to close all accounts that have been 
> inactive for at least a year, without retrieving them one by one?
> Would this approach: 
> 
> POST /account/?inactivityPeriod=365
> Host: myserver.com
> Content-Length: XXX
>    <action>close</action>
> 
> be more appropriate than this one?
> POST /account/
> Host: myserver.com
> Content-Length: XXX
>    <action>closeInactive</action>
>   <inactivityPeriod>365</inactivityPeriod>

If you don't want to retrieve them one by one I think you can do the
same thing, invert an action into a resource with something like:

  GET /accounts/?inactivityPeriod=365

You get back a set of account URLs:

  <accounts>
     <account link="/account/1234" />
     <account link="/account/1235" />
     <account link="/account/1236" />
  </accounts>

Which maybe you can POST to an 'account closing' resource:

  >>
  POST /account-closer
  <accounts>
     <account link="/account/1234" />
     <account link="/account/1235" />
     <account link="/account/1236" />
  </accounts>
  <<
  201 Created
  Location: /account-transaction/2006-09-18-A

  >> 
  GET /account-transaction/2006-09-18-A
  <<
  200 OK
  <transaction status="Closed">
      <resources>
          <account link="/account/1234" />
          <account link="/account/1235" />
          <account link="/account/1236" />
      </resources>
  </transaction>

Since that's a separate resource, you can ask questions of it, like find
the most recent transactions:  

  GET /account-transaction/recent

Or whatever. I'm pretty sure this isn't gospel, but it makes sense to
me, and I think demonstrates the power of the 'resource' abstraction.
 
Chris

Reply via email to