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.
Routing basics
From the course: Building Web APIs with ASP.NET Core 8
Routing basics
- [Instructor] One missing ingredient is routing, or routing depending on where you live. That means which URL maps to which endpoint, to which method, or, as it's called, to which action method, and of course to which controller. There are, of course, several ways to achieve this, but the one I prefer most of the time is just to use attributes. Here is a simple example. We have the route attribute, and we use it like this, Route, and then the ("/products"), and that's basically the URL to call a specific method. So if you use [Route("/products")] or [Route("/products")], and then we have a path or URL fragment, that URL fragment will be routed to the method that follows. We can also use parameters. So if you use /products/ and then in curly braces {id}, now if we call say /products/42, in the action method that follows, we can then have a parameter called id. And the value of that ID parameter is taken from the route. So we call /products/42, then the ID parameter for the action…
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)
-
-