Delete multiple records using REST

前端 未结 5 555
情书的邮戳
情书的邮戳 2020-12-04 08:20

What is the REST-ful way of deleting multiple items?

My use case is that I have a Backbone Collection wherein I need to be able to delete multiple items at once. The

5条回答
  •  余生分开走
    2020-12-04 08:52

    This seems like a gray area of the REST convention.

    Yes, so far I have only come accross one REST API design guide that mentions batch operations (such as a batch delete): the google api design guide.

    This guide mentions the creation of "custom" methods that can be associated via a resource by using a colon, e.g. https://service.name/v1/some/resource/name:customVerb, it also explicitly mentions batch operations as use case:

    A custom method can be associated with a resource, a collection, or a service. It may take an arbitrary request and return an arbitrary response, and also supports streaming request and response. [...] Custom methods should use HTTP POST verb since it has the most flexible semantics [...] For performance critical methods, it may be useful to provide custom batch methods to reduce per-request overhead.

    So you could do the following according to google's api guide:

    POST /api/path/to/your/collection:batchDelete
    

    ...to delete a bunch of items of your collection resource.

提交回复
热议问题