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
From the course: Building Web APIs with ASP.NET Core 8
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…
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)
Controllers and actions7m 50s
-
(Locked)
Routing basics6m 14s
-
(Locked)
Creating a data model5m 54s
-
(Locked)
Using entity framework core7m 28s
-
(Locked)
Returning a list of items4m 4s
-
(Locked)
Using ActionResult2m 44s
-
(Locked)
Returning an item4m 29s
-
(Locked)
Handling errors3m 5s
-
(Locked)
Making the API asynchronous2m 51s
-
(Locked)
Working with minimal APIs5m 22s
-
(Locked)
Challenge: Searching items31s
-
(Locked)
Solution: Searching items3m 1s
-
(Locked)
-
-