7

Is such a thing possible? Did the people who designed REST just think they would delete things one at a time forever?

So let's say I have 10 Foo's ID 1-10

I want to delete ID's 3, 6, and 9 with a single HTTP DELETE call.

Is there any I can do this without offending the Pope?

M. Ryan
  • 6,973
  • 11
  • 52
  • 76

4 Answers4

5

Most APIs I'm familiar with don't allow deleting of multiple entities at a time but to perform other operations on multiple entities with URL parameters like ?id=3,6,9 or ? id=3&id=6&id=9. So it would be fairly common to do either of the following:

DELETE /foos?id=3,6,9

or

DELETE /foos?id=3&id=6&id=9
abraham
  • 46,583
  • 10
  • 100
  • 152
  • 2
    Just bear in mind that such a call won't invalidate cached copies of `/foo/3`, `/foo/6`, and `/foo/9`. – fumanchu Feb 10 '11 at 15:37
  • 1
    @fumanchu But it would be up to the the client to know that. Besides, unless the client deletes the items singularly, ie if they used some for collection resource, the individual resources would have stale caches. But, stale caches are simply part of the web. – thecoshman Jun 27 '13 at 10:37
  • I would also point out, you could just send a payload in the body of the delete request that can be used to detail what exactly to delete. – thecoshman Jul 24 '13 at 14:37
3

You could also DELETE /Foos?id=3,6,9.

weltraumpirat
  • 22,544
  • 5
  • 40
  • 54
0

I don't think it's a problem.

DELETE http://www.example.com/foos means delete all.

DELETE http://www.example.com/foos{3,6,9} means delete foo 3, 6, 9.

Dagang
  • 24,586
  • 26
  • 88
  • 133
  • 1
    Are those brackets {#,#,#} part of the standard? I've never seen that before. – M. Ryan Feb 10 '11 at 06:52
  • It's just normal URI part. Any resource and resource collection can be represented with URI, you can give semantics to the URI. – Dagang Feb 10 '11 at 07:00
  • 2
    @Todd the additional data in the URI like that looks messy, would you not prefer sending the data for what to actually delete within the body of the request? This is what I am strongly considering for a system where the default use case will be multiple deletes. I also intend to make just calling 'DELETE /foos` without a body an 'invalid' action. – thecoshman Jul 24 '13 at 14:36
  • `DELETE http://www.example.com/foos` seems like a very dangeous, easy to fat-finger operation. Other answers on here indicate a two step approach: http://stackoverflow.com/questions/2421595/restful-way-for-deleting-a-bunch-of-items – Tommy Jan 25 '17 at 02:04
-3

If you are concerned about offending the pope, maybe you should spend some time reading the scriptures :-) https://datatracker.ietf.org/doc/html/draft-gregorio-uritemplate-04

I think all your questions will be answered in there.

Community
  • 1
  • 1
Darrel Miller
  • 139,164
  • 32
  • 194
  • 243
  • 4
    Could you indicate the exact place in the aforementioned document answering the OP's question? – mark Jan 02 '13 at 10:41
  • @mark Look for all the expansion samples that use the example variable `list`. There are many ways to expand multiple values in a URI template. http://tools.ietf.org/html/rfc6570 – Darrel Miller Jan 02 '13 at 15:26
  • @DarrelMiller so comma delimited key-pairs in form field style? should deletion be wrapped in transactions with two status types: success, failure? (ie. no partial success) – Jonathan Mui Feb 11 '13 at 07:01