Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

REST Architecture for Multiple Deletes?

I send a delete request to server as like:

@RequestMapping(value = "/user/{userId}", method = RequestMethod.DELETE)

for a single user delete. However what to do when multiple users wants to be deleted? I want to obey REST architecture but I want to see the another ways from sending multiple delete requests?

PS: Is this a suitable way:

@RequestMapping(value = "/user", method = RequestMethod.DELETE, headers = "Accept=application/json")
    public void deleteUser(HttpServletResponse response, @RequestBody String users) throws IOException {
        ...
}
like image 878
kamaci Avatar asked Sep 22 '11 07:09

kamaci


People also ask

How do I delete data from REST API?

In REST API DELETE is a method level annotation, this annotation indicates that the following method will respond to the HTTP DELETE request only. It is used to delete a resource identified by requested URI. DELETE operation is idempotent which means. If you DELETE a resource then it is removed, gone forever.

Can rest delete have request body?

Yes it is allowed to include a body on DELETE requests, but it's semantically meaningless.


1 Answers

since rest is resource oriented arch.

try design a higher level domain object which represents 'multiple users' resource ,

do delete on that object.

maybe

@RequestMapping(value = "/users/expired", method = RequestMethod.Delete)

the great book 'restful web services cookbook' by Subbu Allamaraju , oreilly , talk about this topic:

  • chapter 11.10, how to batch process similar resources;
  • chapter 11.11, how to trigger batch operation;
  • chapter 11.12, when to use post to merge multiple request ;
  • chapter 11.13, how to support batch request
like image 167
swanliu Avatar answered Oct 10 '22 15:10

swanliu