Restful way for deleting a bunch of items

后端 未结 8 1101
栀梦
栀梦 2020-12-04 05:26

In wiki article for REST it is indicated that if you use http://example.com/resources DELETE, that means you are deleting the entire collection.

If you use http://ex

相关标签:
8条回答
  • 2020-12-04 06:05

    One option is to create a delete "transaction". So you POST to something like http://example.com/resources/deletes a new resource consisting of a list of resources to be deleted. Then in your application you just do the delete. When you do the post you should return a location of your created transaction e.g., http://example.com/resources/deletes/DF4XY7. A GET on this could return the status of the transaction (complete or in progress) and/or a list of resources to be deleted.

    0 讨论(0)
  • 2020-12-04 06:09

    I think rojoca's answer is the best so far. A slight variation might be, to do away with the javascript confirm on the same page, and instead, create the selection and redirect to it, showing a confirm message on that page. In other words:

    From:
    http://example.com/resources/

    do a

    POST with a selection of the ID's to:
    http://example.com/resources/selections

    which, if successful, should respond with:

    HTTP/1.1 201 created, and a Location header to:
    http://example.com/resources/selections/DF4XY7

    On this page you will then see a (javascript) confirm box, which if you confirm will do a request of:

    DELETE http://example.com/resources/selections/DF4XY7

    which, if successful, should respond with: HTTP/1.1 200 Ok (or whatever is appropriate for a successful delete)

    0 讨论(0)
提交回复
热议问题