Updating multiple items with RESTful

What should be the correct RESTful approach when trying to update / delete more than one item?

A typical example: there is a list of elements, a folder for the income of received messages, where you can select a group of them by checking the corresponding boxes. Then you click the "delete" button and send a petition to delete them. What method should I name? What settings?

In this case, it is pretty obvious what I should use DELETE, but it only works with one element at a time. In addition, I do not want to delete them, but I save them in another folder, which may mean use PATCH, but again, the method PATCHallows only one element.

+4
source share
3 answers

In this case, it is pretty obvious that I have to use DELETE, but this only works with one element at a time. In addition, I do not want to delete them, but saving them in another folder, which may mean using PATCH, but again, the PATCH method only allows one item.

You must REPEAT the collection (or part of it), not the item. For example, by moving items you can use PATCH /collection/?filter=x {location: newDir}. DELETE is a tricky question. You can use PATCH or an alternative to use DELETE /collection/?filter=x, but that means that you want to delete the collection resource and not remove the element resources from it. When creating the package, I think the use POST /collection/ [item1, item2, ...]is ok.

Ofc. URI-, PATCH /books/1+2+3/ {price: 20, currency: "EUR"}. PATCH, , PATCH /collection/?filter=x {op: "update", location: newDir}. , PATCH URI, . , . POST /transactions/ HTTP-.

, , , , , - . , , , .

+2

. , , , , , DELETE https://host.com/messages/1;2;3 1, 2 3.

+1

To delete / update you should always use POST methods. Pass the id and action (update / delete) values โ€‹โ€‹of the messages you want to use the POST method. Extract the elements and update tthem as objects in memory, then click on the changes in db.

-2
source

Source: https://habr.com/ru/post/1617949/


All Articles