From the course: Building Web APIs with ASP.NET Core 8

Unlock the full course today

Join today to access over 24,400 courses taught by industry experts.

Updating an item with PUT

Updating an item with PUT

- [Instructor] When updating items, in our case products, we need to think about our strategy first. What kind of arguments do we provide to our action method? Here is what I recommend. We have here an action method, and I call it put product because the put HTTP method is responsible for updates. And of course we need HTTP put as an attribute to make sure that put requests are routed here. We are also using a route template, so slash API slash products slash and then the ID of the product we would like to update, remember slash API slash product slash 42 is the URI that represents a specific product. If you would like to update that product, that is the URI we should use. So now we know that the product with a given ID shall be updated but with what? We need, well the new product, the updated product. So the second argument will be a product, something of our data type product and that will contain name and description, et cetera. And that will be written to the database. We are not…

Contents