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
From the course: Building Web APIs with ASP.NET Core 8
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…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
(Locked)
HTTP methods3m 8s
-
(Locked)
Model binding4m 31s
-
(Locked)
Adding an item with POST12m 14s
-
(Locked)
Model validation5m
-
(Locked)
Updating an item with PUT7m 59s
-
(Locked)
Deleting an item with DELETE4m 45s
-
(Locked)
Migrating the code to Minimal APIs6m 21s
-
(Locked)
Challenge: Deleting several items41s
-
(Locked)
Solution: Deleting several items5m 40s
-
(Locked)
-