From the course: Mastering Nest.js: Build Scalable Applications with Mastery in Nest.js Framework

Unlock this course with a free trial

Join today to access over 25,200 courses taught by industry experts.

Deleting the product

Deleting the product

Now, let's see how to implement the delete functionality. We already have specified the delete handler with a route. Let me open the home EJS file where we have defined the anchor tag for delete. Now as you may know, the anchor tags in HTML are bound to the get method. They are used to navigate to a different URL, which results in a get request being sent to the server. This means they cannot directly perform other HTTP methods such as delete, post or put. So to make a delete request, we have only few options. Either we make use of a form tag or bind a separate method with onClick that handles the delete request. We are going to use the form tag as we are already using the method override middleware. So I'll remove this anchor and instead I'll give the form tag setting the route to slash product slash delete and will bind the product.id with scriptlet and the query that is underscore method equal to delete. Then I'll set the method to post and class as display line to maintain the…

Contents