# 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 November 14, 2026

Deleting a record should be done through a DELETE request. When a client DELETEs a record - the id should be included in the URL

![A DELETE request is a header only: the verb DELETE and the address of the category, /categories/10](https://fsdtrainingmedia.blob.core.windows.net/public/images/2026/09/55a370e9a8ca4d489a1f0e49a4249193.png "A DELETE request is a header only: the verb DELETE and the address of the category, /categories/10")

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

![The server answers 204 (no content), with no body](https://fsdtrainingmedia.blob.core.windows.net/public/images/2026/09/ecdefeaa5223429f9396e07a8e388201.png "The server answers 204 (no content), with no body")

## DELETE Request - Client

In Insomnia, this is your `Delete Snacks` request from *Insomnia: DELETE*, with no body:

```text
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)

```java
@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.

![Insomnia shows 204 No Content and an empty body after DELETE /api/categories/10](https://www.ask-codey.com/lessons/TODO)

## Cheat sheets

- [PUT and DELETE](https://www.ask-codey.com/cheat-sheets/restful-web-apis-put-insomnia-cheat-sheet)

Source: https://www.ask-codey.com/lessons/restful-web-apis-delete
