Introduction to Delete Method

Implement the delete operation for the User entity.

The last CRUD operation

After implementing create, read, and update, we’ve come to the last part of the CRUD formation: Delete.

There is an issue, though. Web browsers only support GET and POST.

We don’t get to use all the other HTTP request methods (or HTTP verbs as they are sometimes called) that REST API developers can use.

Alternate options

Fortunately, we have two options to work around this limitation:

  • Use a dedicated URL: For example, we can allow a POST on /users/<id>/delete to delete a user.

  • Do a POST with the real method as an additional parameter (modeled as a hidden input field in an HTML form).

Using a dedicated URL

This first example will use a dedicated URL as it requires no special support from Spring Boot to make it work. We can just add a new PostMapping to UserController:

Get hands-on with 1200+ tech skills courses.