1

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?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Mihail Zheludev
  • 166
  • 3
  • 10

1 Answers1

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 the JSON 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