From the course: Building RESTful Web APIs with Django

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Connecting a DestroyAPIView to the router

Connecting a DestroyAPIView to the router

From the course: Building RESTful Web APIs with Django

Start my 1-month free trial

Connecting a DestroyAPIView to the router

- [Instructor] Let's connect the destroy product API view to the router, so that we can start using it in our API. In the URL's configuration we add a new URL path with the lookup field so that we can destroy a product using the ProductDestroy API view. With the server running let's try this out on the browser. First we find the ID of an existing product, and then we can delete the product. We click the destroy button and confirm the action. We can also delete products through a curl command on the command line. Let's create a new product and then delete it. We use the POST method to create the product as we did before. The product is created, so now we can use the returned ID and delete it. So, we use the DELETE method with our URL for product deletion. And then hit enter, and it looks like the product is deleted now. And that's how we delete a product through the browser, and through the command line using the REST API.

Contents