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 {
...
}
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.
Yes it is allowed to include a body on DELETE requests, but it's semantically meaningless.
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:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With