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

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…

Contents