Search code examples
restrestful-architecture

REST: How to handle an action changing multiple resources


I am trying to understand the resource-based RESTful architecture. I understand that an HTTP GET on /accounts will list the accounts and GET on /accounts/123 will provide details on the given account. How do I implement active management in RESTful architecture, like transfer money from account A to account B?


Solution

  • Consider the idea of declaring the transaction itself as a resource, so that you could operate on your single resource atomically:

    POST /transaction
    
    -> /transaction/456
    

    I suggest avoiding HTTP PUT in this case because idempotency is not what we want for this resource.

    Posting the new transaction will update the account A and B.