What is the REST-ful way of deleting multiple items?
My use case is that I have a Backbone Collection wherein I need to be able to delete multiple items at once. The options seem to be:
All options are less than ideal.
This seems like a gray area of the REST convention.
First of all you need to create a jpa query method that brings all records belong to id. After that you can do deleteAll() operation on List.
Use the sObject Rows resource to delete records. Specify the record ID and use the DELETE method of the resource to delete a record.
/records/1;2;3
” — So a 2xx response to this may cause them to purge their cache of /records/1;2;3
; not purge /records/1
, /records/2
or /records/3
; proxy a 410 response for /records/1;2;3
, or other things that don't make sense from your point of view.records=[1,2,3]
to /delete-requests
) and poll the created resource (specified by the Location
header of the response) to find out if your request has been accepted, rejected, is in progress or has completed. This is useful for long-running operations. Another way is to send a PATCH
request to the list resource, /records
, the body of which contains a list of resources and actions to perform on those resources (in whatever format you want to support). This is useful for quick operations where the response code for the request can indicate the outcome of the operation.Everything can be achieved whilst keeping within the constraints of REST, and usually the answer is to make the "problem" into a resource, and give it a URL.
So, batch operations, such as delete here, or POSTing multiple items to a list, or making the same edit to a swathe of resources, can all be handled by creating a "batch operations" list and POSTing your new operation to it.
Don't forget, REST isn't the only way to solve any problem. “REST” is just an architectural style and you don't have to adhere to it (but you lose certain benefits of the internet if you don't). I suggest you look down this list of HTTP API architectures and pick the one that suits you. Just make yourself aware of what you lose out on if you choose another architecture, and make an informed decision based on your use case.
There are some bad answers to this question on Patterns for handling batch operations in REST web services? which have far too many upvotes, but ought to be read too.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With