Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Deleting multiple resources during a single request in a RESTful service

Tags:

rest

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?

like image 491
Larry Foulkrod Avatar asked Feb 03 '11 21:02

Larry Foulkrod


People also ask

How do I delete multiple records using postman?

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.

How do I delete data from REST API?

Use the sObject Rows resource to delete records. Specify the record ID and use the DELETE method of the resource to delete a record.

Which methods are used to delete resources by ID?

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.


2 Answers

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/
like image 146
S.Lott Avatar answered Sep 28 '22 08:09

S.Lott


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?

like image 42
Lee Kowalkowski Avatar answered Sep 28 '22 09:09

Lee Kowalkowski