4

This is a follow up question to : Transactions in REST?

How does one implement a REST API that offers full transaction capabilities to it's clients?

For example, if a client wants to create a transaction that will do the following operations:

  • create one or more objects.
  • update one or more objects.
  • delete one or more objects.

While it's a valid requirement for a transaction, it seems to break the REST requirements to use PUT to create, POST to update and DELETE to delete.

My current solution involves handling the entire system as one hierarchical object structure and using the POST operation. For example:

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, this satisfies most REST requirements except for the "delete" flag which isn't really a piece of data.

I'm curious to know if anyone found a better solution.

Community
  • 1
  • 1
Steve McDuff
  • 338
  • 2
  • 11
  • 1
    The answers to [this question](http://stackoverflow.com/questions/147207/transactions-in-rest) suggest using a server side transaction object which you update with the single operations and then submit. Also has its downsides of course. – Jan Gerlinger Jul 16 '12 at 12:33
  • Yes, I've read this suggestion of a "Transaction" object that would contain a sequential list of operations to do. I feel that my current solution is much closer to the REST philosophy than a virtual "Transaction" object which doesn't really map to the application domain. However, the transaction object has the added benefit of explicitly specifying the order in which each step should be executed. – Steve McDuff Jul 18 '12 at 13:27

1 Answers1

0

Agree With Jan that you need to handle at the serverside.but down side is badly maintainble code.Yes my experience with Restful applications suggest that adhering to PUT & DELETE verbs in RESTFul Architecture is pretty tough as various browser version support is far limited for them.