This is the next question: Transactions in REST?
How to implement a REST API that offers all the transaction features for it?
For example, if a client wants to create a transaction that will perform the following operations:
- create one or more objects.
- update one or more objects.
- delete one or more objects.
While this is a valid requirement for a transaction, it seems to violate the REST requirements for using PUT to create, POST to update, and DELETE to delete.
My current solution involves processing the entire system as one hierarchical structure of an object and using the POST operation. For instance:
POST /system { "Users" : [ { "ID":"123", "name":"bob" // update the user with ID matching 123, // set his name to "bob" }, { "ID":"456", "delete":"true" // trigger a delete on user with ID 456 } ], "Products" : [ { "name":"foo" // create a product named "foo" since no ID is provided }, ] }
So far, it satisfies most REST requirements, with the exception of the βdeleteβ flag, which is not really part of the data.
I am curious to see if anyone has found a better solution.
source share