@DeleteMapping is a Spring MVC annotation that maps HTTP DELETE requests to a controller method. It is a shortcut for @RequestMapping(method = RequestMethod.DELETE) and was added in Spring Framework 4.3. You use it in REST controllers to remove a resource, usually identified by a path variable such as /users/42.
A well-behaved delete endpoint returns 204 No Content on success and 404 Not Found when the resource does not exist. It should also be idempotent, so repeating the same request leaves the system in the same state.
@DeleteMapping belongs to the family of composed mapping annotations in org.springframework.web.bind.annotation: @GetMapping, @PostMapping, @PutMapping, @PatchMapping and @DeleteMapping. Each sets the HTTP method and takes the same attributes as @RequestMapping, including value (or path), produces and consumes.
It works on methods of classes annotated with @RestController or @Controller. A class-level @RequestMapping supplies the common prefix, and the method-level path is appended to it.
The example uses Spring Boot 3, a service layer and Spring Data JPA. The controller stays thin and the service decides what happens when the id does not exist.
A request and its responses look like this:
A second call for the same id returns 404 Not Found in this design. Some teams prefer to return 204 again, because the end state is identical. Either choice is valid as long as you document it.
| Situation | Typical status |
|---|---|
| Resource deleted, nothing to return | 204 No Content |
| Deleted and you return a body, such as the removed item | 200 OK |
| Deletion queued for background processing | 202 Accepted |
| Resource does not exist | 404 Not Found |
| Caller is not allowed to delete it | 403 Forbidden |
| Resource is referenced elsewhere and cannot be removed | 409 Conflict |
When the method returns void, you can set the status declaratively instead of using ResponseEntity:
Here deleteOrThrow throws a custom exception that an @RestControllerAdvice turns into a 404 response, ideally as a ProblemDetail (RFC 9457 format, supported in Spring Framework 6).
A delete usually targets a path, but you can use other inputs:
@RequestParam for bulk or filtered deletes, for example DELETE /api/sessions?userId=7.POST /api/users/bulk-delete endpoint with a JSON list is often more portable.@PreAuthorize.deleted_at column) when you need audit trails or recovery. The endpoint stays the same.None at runtime. @DeleteMapping is a composed annotation that sets the method for you and is shorter to read.
204 No Content is the most common. Use 200 OK if you return a body, or 202 Accepted if deletion is asynchronous.
Yes by HTTP definition. Calling it repeatedly must leave the server in the same state, even if the later responses differ.
Usually CSRF protection or CORS. Send the CSRF token with the request or configure Spring Security to match your authentication style.
@DeleteMapping maps DELETE requests to controller methods and keeps REST endpoints short and readable. Return 204 or 404 deliberately, keep deletes idempotent, authorise on the server, and handle errors centrally with @RestControllerAdvice.