October 2015
Intermediate to advanced
128 pages
2h 36m
English
It will come as no surprise that we use the DELETE verb to delete REST resources. Also, you will have already figured out that the path to delete requests is /rooms/{roomId}.
The Java method that deals with room deletion is shown as follows:
@RequestMapping(value = "/{roomId}", method = RequestMethod.DELETE)
public ApiResponse deleteRoom(@PathVariable long roomId) {
try {
Room room = inventoryService.getRoom(roomId);
inventoryService.deleteRoom(room.getId());
return new ApiResponse(Status.OK, null);
} catch (RecordNotFoundException e) {
return new ApiResponse(Status.ERROR, null, new ApiError(999, "No room with ID " + roomId));
}
}By declaring the request mapping method to be RequestMethod.DELETE, Spring will make this method handle ...
Read now
Unlock full access