DELETE
Handle a DELETE request with @DeleteMapping, taking the category's id from the URL, and answer 204 No Content.
Journeyman · Spring Boot · REST API · Updated
Deleting a record should be done through a DELETE request. When a client DELETEs a record - the id should be included in the URL

The server will delete the data, then it will return a status of no content (204).

DELETE Request - Client
In Insomnia, this is your Delete Snacks request from Insomnia: DELETE, with no body:
DELETE {{ _.base_url }}/api/categories/10
DELETE Request - Server
The method responsible for handling the request must be marked with a @DeleteMapping annotation to handle the request. The id of the resource must be marked as a @PathVariable. The @ResponseStatus annotation specifies the status code that will be returned (HttpStatus.NO_CONTENT returns a status of 204)
@DeleteMapping(path="/api/categories/{id}")
@ResponseStatus(value = HttpStatus.NO_CONTENT)
public void deleteCategory(@PathVariable int id)
{
// the DAO deletes the row; nothing is returned
categoryDao.delete(id);
}
DELETE Response - Client
Add the method to your controller and the delete method to your DAO, run the app again, and send Delete Snacks. The 405 Method Not Allowed from Insomnia: DELETE is now 204 No Content, and the body is empty. Then send All categories: category 10 is gone from the list.