Reputation: 1315
I have sales orders that my customers can submit and then edit at a later date. When inserting the edits into the database, I am choosing to completely remove all line items from the sales order and insert them all again as if it were a new order.
to illustrate:
an initial order of..
ORDERID: 1
Lines:
10. item 1 - 45qty
20. item 2 - 50qty
30. item 7 - 33qty
40. item 9 - 65qty
then the customer edits the order: (changes qty of item 1, removed item 9 and adds item 4)
ORDERID: 1
Lines:
10. item 1 - 60qty
20. item 2 - 50qty
30. item 4 - 10qty
40. item 7 - 33qty
My api will first call a SQL command to DELETE FROM [table] WHERE ORDERID = @OrderID
then it will loop through all the lines from the edit and insert them to the order. Just like it would if it were doing the initial insert when creating a new order.
So my question is... should i use the HTTP verb UPDATE to do this? or PUT? or what would be appropriate?
Upvotes: 0
Views: 172
Reputation: 1096
I think that HTTP PUT
is exactly for your case. If you want to update the existing objects then use PATCH
.
From REST API design doc:
The HTTP RFC specifies that PUT must take a full new resource representation as the request entity. This means that if for example only certain attributes are provided, those should be removed (i.e. set to null).
An additional method called PATCH has been proposed recently. The semantics of this call are like PUT inthat it updates a resource, but unlike PUT, it applies a delta rather than replacing the entire resource. At the time of writing, PATCH was still a proposed standard waiting final approval.
Upvotes: 1