Jason Posit
Jason Posit

Reputation: 1323

My grudge with REST: am I right here or am I missing something?

I am designing a data-centric application that stores sale orders on a server. At any time the client may decide to modify a sales order, perhaps because they receive a phone call from the purchaser requesting additions, modifications, and deletions, associated with the sale order. Thus each Sale database table on the server has a SaleItems detail table where the sale items are stored.

Now REST methods GET, POST, PUT, and DELETE are supposed to correspond roughly to SQL SELECT, INSERT, UPDATE, and DELETE statements to be carried out on the server when the corresponding objects change.

If I use REST, when the order changes I would have to do a PUT to update the sale item, thus calling an UPDATE statement. But then the PUT would also need to: 1. delete all old items appearing as purchase items, with their item quantities and item prices, and then 2. insert all the new items with their quantities and prices. Thus a PUT actually corresponds to an UPDATE, DELETE, and multiple INSERTs (and I cannot think of another better way to do this). So, so much for rest.

I cannot separate the SQL UPDATE, DELETE, and INSERTs because the operation needs to be atomic and run within a single transaction, so I cannot do an HTTP PUT, a DELETE, and multiple POSTS, as that would be impractical.

So, when the HTTP operations do not correspond to the SQL operations in a neat manner, what is the whole purpose of REST as opposed to XML-RPC??? Have I misunderstood REST?

Thanks for your views.

Upvotes: 1

Views: 87

Answers (1)

Andomar
Andomar

Reputation: 238206

I cannot separate the SQL UPDATE, DELETE, and INSERTs because the operation needs to be atomic and run within a single transaction

You do misunderstand REST. REST means REpresentational State Transfer. In REST, you cannot modify an order by sending a command to delete an order line. That would mean sending unrepresentional state.

Instead, you send the complete order with all changes you've made. In other words, you Transfer a REpresentation of the State of the order. Sending a change that way is transactional.

Upvotes: 1

Related Questions