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

Unlock the full course today

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

Working with minimal APIs

Working with minimal APIs

- [Instructor] We have reached a first milestone with our controller-based API. We can retrieve all products and a single product. Now how about we migrate this to minimal API so that you see the same thing, but using the alternative approach for creating APIs with ASP.NET Core. In Program.cs, what we need to do is, we have to add several calls to app.Map and then Get, which basically maps a get request to an endpoint. So far, we have the endpoint/api/Products, et cetera. How about we skip the /api for the minimal APIs? So just /products, and then we have to provide the implementation here. We can do that as a Lambda expression. But don't we use the ShopContext somehow? How do we get that? How is that possible or feasible? Well, what we can do is, we can use dependency injection again, and here's how that is working. We just get the ShopContext as a parameter here, automatically. If we want to do that asynchronously, we can do async, and then adjust return await…

Contents