api design - REST Partial update on multiple resources -
i have 2 sorts of resources, stores , items, store can uniquely identified by it's id, store contains number of different types of items.items have codes identify type , instance conductor cable of modela has code of 265, item of code 265 can exist in more 1 store. sample http requests , responses.
get /stores/1/items [{ "itemcode": 265, "itemdescription": "conductor cable", "itemmodel": "model1", "uom":"meter", "quantity": 30 }, { "itemcode": 122, "itemdescription": "low-fat milk", "itemmodel": "model2", "uom":"liter", "quantity": 15 }] /stores/2/items [{ "itemcode": 265, "itemdescription": "conductor cable", "itemmodel": "model1", "uom":"meter", "quantity": 25 }] /stores/3/items [{ "itemcode": 122, "itemdescription": "low-fat milk", "itemmodel": "model2", "uom":"liter", "quantity": 20 }]
what have rest api endpoint let api consumer move, 10 meters of conductor cable of model1 store 1 store 2. know there option of having 2 patch http requests achieve updating quantities in stores 1 , 2 need achieve single http request.
if want achieve using http patch json patch - rfc 6902 should prove helpful. allows sending multiple operations within single request possible update multiple resources , properties @ same time. if operation fails whole patch should fail well. within request have specify new final quantity of item. can't define operation subtract current value. in order solution work in multiuser environment optimistic locking mechanism must. otherwise data corruption bound happen.
http post alternative. moving quantity of item 1 store akin transfering money between bank accounts. in case consider creating following endpoint: post /stores/item-transfer
. request body contain source store/itemcode/itemquantity , target store. state modifications happen within single transaction.
personally i'm in favor of post approach if stick patch , java language i'd suggest using tomoko library process rfc 6902 requests. i'm author.
wiki
Comments
Post a Comment