tags:

views:

62

answers:

2

I have a client-side interface that allows the user to perform multiple edits against a tree-like outline. I consider the aggregate of the records making up that outline, in totality, a single resource (/outlines/39) even though its parts could be accessed as separate resources via different URLs.

The problem is the user can edit existing nodes in the outline as well as add new nodes to the outline. Normally, when you edit something you PUT its changes and when you add something new you POST it; however, in some cases you'll want to wrap all the changes--including both adds and edits--in a single transaction. What are some practical ways people have handled this?

Even though the outline already exists and a PUT seems appropriate, the embedded adds violate the idempotence of the PUT. I'm not sure that POST seems appropriate either. For design purposes, I have decided not to save each discrete update the user makes though I guess this offers one solution. Still, there must be others who have dealt with my issue or have ideas about it.

+1  A: 

Is there any way you could make the add idempotent? E.g. if nodes had a natural key, then when the client tried to add a node a second time you could do nothing.

Alex Black
No natural key, but this lead me to consider that the server (or client) could dish out temporary guids as I create new nodes. In this way a record would be identifiable by its id and guid. By using the guids, I don't end up consuming ids if the user fails to commit the entire transaction. On that note, it begs the question of using a guid as the PK instead of an identity seed. Will give it some thought. Thanks.
Mario
Interesting! Glad I could help.
Alex Black
After further investigation I've decided a PUT is only ever right if you're PUTting the resource in its entirety. Since I'm only PUTting back the delta (added/updated/deleted nodes), I think it makes more sense to PUT that delta back to a sub-resource URL, similar to your transaction sub-resource suggestion. I haven't worked out the details yet.
Mario
A: 

How about: make a new resource: /outlines/39/transactions, and POST your transaction to that resource, e.g.

POST "addNode=node1, addNode=node2, editNode=node3,newName=foobar" to /outlines/39/transactions

Alex Black