I'm wondering about deletion of bunch items using REST API. But I can't find right way. I'm implementing this just by POST method. And it seems as deviation from REST nature. Is there some way with DELETE method for deletion of a collection?
Asked
Active
Viewed 5,333 times
1
-
1Check this question : http://stackoverflow.com/questions/21863326/delete-multiple-records-using-rest – Milad Alshomary Sep 18 '15 at 10:35
-
thanks @MiladAlshomary, now it' clear – Mihail Zheludev Sep 18 '15 at 11:24
1 Answers
1
I see two ways to do that with REST:
If you want to delete all the elements, you can use the method
DELETE
on a list resource itself. For example:DELETE /contacts/
will remove all contacts.If you to delete only a subset, you can leverage the
PATCH
method and theJSON PATCH
format (see http://jsonpatch.com/ and https://www.rfc-editor.org/rfc/rfc6902) to specify which elements to delete. Here is a sample:PATCH /contacts [ { "op": "remove", "path": "/contacts/1" }, { "op": "remove", "path": "/contacts/2" }, { "op": "remove", "path": "/contacts/3" } ]
The following could give you some hints: https://templth.wordpress.com/2015/05/14/implementing-bulk-updates-within-restful-services/.
Hope it helps you, Thierry

Community
- 1
- 1

Thierry Templier
- 198,364
- 44
- 396
- 360