Suppose we have a Invoice that is saved in a draft state in a RDBMS. The invoice has three line items. A rest client gets the invoice, and modifies the line items.
GET /invoice/123
{
"InvoiceId" : "123",
"lineitems":
[
{ "id":"A", "qty":"5"},
{ "id":"B", "qty":"5"},
]
}
Assume user modifies the invoice as follows;
Changes quantity of Item A
Removes Item B.
Adds new item C.
The result is:
{
"InvoiceId" : "123",
"lineitems":
[
{ "id":"A", "qty":"10"},
{ "id":"D", "qty":"5"},
]
}
The net change is that a line has been deleted, a line has been updated, and a line has been added.
User then saves the draft invoice, which results in a PUT request.
PUT /invoice/123
What is the best strategy to update the line items on the server?
Keep in mind that deleteing all line items and creating them from scratch will loose any meta data on those lines (Created by, Created date, last modified by…)
Thanks,
http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html
Think of
PUTas replace. The state of the resource in thePUTrequest should be the resulting state of the resource if it is accepted.If you want to add/remove/update specific elements you should look into using
PATCH.