Using the DELETE HTTP Method
Learn how to perform the DELETE operation using the HTTP method.
We'll cover the following
In the previous lesson, we used /users/<id>/delete
as the URL to POST
to.
We will show an alternative
implementation in this section that does the more restful thing of issuing a DELETE
on
/users/<id>
.
Turning POST into DELETE
As browsers only allow GET
and POST
, we need support from Spring Boot to turn the POST
from the
browser into a DELETE
. This support comes in the form of the HiddenHttpMethodFilter
class and
can easily be enabled by setting the spring.mvc.hiddenmethod.filter.enabled
property in the
application.properties
file:
spring.mvc.hiddenmethod.filter.enabled=true
We can update UserController
to map our doDeleteMethod
on the DELETE HTTP
method:
Get hands-on with 1400+ tech skills courses.