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.
Migrating the code to Minimal APIs
From the course: Building Web APIs with ASP.NET Core 8
Migrating the code to Minimal APIs
- [Instructor] We have completed our API as a controller based API. But as promised, I would also like to show you how this looks when using the minimal API approach. And instead of you watching me copy and paste code over from the controller to program CS, and then changing a few things, I just did that before and I just showed you the highlights, what I did. And I would like to do this from the bottom to the top. So I start with the last HTTP method we were using, Delete. So for delete I am just calling in program CS, of course. App.macdelete, which is responsible for delete HCP requests. I provide the URI, and it'll be slash product slash id, remember our controller based API was API slash product slash id. So that's the difference here. And then in the handler method, I of course expect the ID as an argument, but I also need the database context. So I'm using dependency injection like this so that I can access it. And the remainder of the method is essentially the same. I just was…
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)
-