I'm looking for examples of how others have created a RESTful service that supports deleting multiple entities of the same type in a single request. For example if I were writing an email service I may want to be able to delete multiple messages at the same time.
One way to handle this could be have a resource that is defined as "a collection that contains the mail items identified by the specified id values". This resource could have the following interface:
GET /api/mail/1;2;5;38 - return the collection of items DELETE /api/mail/1;2;5;38 - delete the collection of items
Is this a common way of handling multiple deletes? What are some other ways people have seen this done?
One method is to create a 'change request' resource (e.g. by POSTing a body such as 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.
Use the sObject Rows resource to delete records. Specify the record ID and use the DELETE method of the resource to delete a record.
In RESTful APIs resources are typically deleted using the HTTP DELETE method. The resource that should be deleted is identified by the request URI. DELETE is an idempotent HTTP operation. Sending the same DELETE request multiple times should only alter the server state once.
It feels a little odd because the RESTful URI doesn't name a "resource", but rather a collection of resources.
While it feels a little odd, I think there are no better ways to specify that kind of "collection".
We do things like that also -- some of our path levels are "ranges" or "sets" or "filter functions".
/path/to/resource/in:filter;filter;filter/
Perhaps you can define a new resource that represents a collection of the resources that have been marked for deletion, and then delete that resource to delete them?
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