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 CreateAPIView to the router

Connecting a CreateAPIView to the router

From the course: Building RESTful Web APIs with Django

Start my 1-month free trial

Connecting a CreateAPIView to the router

- [Narrator] Now we can create a route in the URL configuration for creating a product through the product create API view. We add a new URL path that points to the product create view. With that done, let's run the server. To test the API to create a new product, let's use the curl command on the console. We set the method to post and point to the API URL that we just added. We set the price to one dollar, set the product name to 'My Product', and set the description 'Hello World'. As you can see we get a response from the API indicating that the product was created. This is something I do very often when I work with Rust APIs. The development team shares the curl scripts with each other so we can quickly create new models and test APIs to make sure they are working correctly. Now, let's see how this looks in the browser. Django REST Framework provides a nice interface that makes it easy for us to test creating new products. So you can see we have a nice form with multiple fields for…

Contents