January 2018
Intermediate to advanced
414 pages
10h 29m
English
In our initial definition, we said that if we are going to delete a resource that is not found, we should answer with 404 NOT FOUND, and if we delete it, we should answer a 200 OK, regardless of whether we should need to send a body back to the client.
So, our method will look like this:
@DeleteMapping(value = "/customer/{id}")fun deleteCustomer(@PathVariable id: Int): ResponseEntity<Unit> { var status = HttpStatus.NOT_FOUND if (customerService.getCustomer(id) != null) { customerService.deleteCustomer(id) status = HttpStatus.OK } return ResponseEntity(Unit, status)}
First, we will set that we have not found the customer, and we will check with our service if it actually exists. If so, we delete and set the status ...
Read now
Unlock full access