From the course: Build Modern Web Apps with React, Hooks, State Management, and APIs Using Vite or Next.js

Unlock this course with a free trial

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

Adding a product: POST

Adding a product: POST

Hello and welcome back. In this video, we are going to see how we can add a product using a HTTP POST method. For adding a product, we need to have a form set up. This form will be taking the values such as name, quantity, description and price. Based on these value, we can have a form setup and on add button or on save button, we can actually call the API like this. In the submit button, we are having the API client instance and we are calling dot post method of it. And we have to provide two things here. One is the resource that where we want to add it and the next is the body data which is going to be the request body and this body is going to have the data that we want to add to that resource. Let's take a look at the code. We can close this down and we can have opened the add product.tsx file. We have a form setup and in this useState object we have name, quantity, price and description. We are displaying all the elements here inside the form and on submit of event of the form we…

Contents