January 2018
Intermediate to advanced
414 pages
10h 29m
English
When we use the HTTP DELETE, we are asking our service to delete a given resource, and we will do it in the form of /customer/id. This specifies which resource needs to be deleted among all of them:
@RequestMapping(value = "/customer/{id}", method = arrayOf(RequestMethod.DELETE))fun deleteCustomer(@PathVariable id: Int) = customers.remove(id)
For this operation, we have just set the corresponding HTTP verb in the method, and as a path variable, the id of the resource to be deleted. Then, we simply remove it from our customer map. We don't need to have any customer as a body parameter since with the id, we could just remove our resource.
We could test this operation sending a simple request using cURL:
curl -X DELETE http://localhost:8080/customer/4 ...
Read now
Unlock full access