From the course: Advanced Web APIs with ASP.NET Core in .NET 6
Unlock the full course today
Join today to access over 24,800 courses taught by industry experts.
Implement URL versioning - C# Tutorial
From the course: Advanced Web APIs with ASP.NET Core in .NET 6
Implement URL versioning
- [Christian] Let's start with, well, at least according to my preferences, the second best option, using the URL for version information. With the NuGet package we just installed, most of the actual work is already done. We just need to do some extra configuration. We start with our products controller, which is marked with the ApiController attribute. What we now do is we add another attribute called ApiVersion. And that attribute receives the version number we intend to use as a parameter. We could also provide a Route, and in that Route we can access the version number. So in our case, the API version is set to 1.0. And so the Route for this controller is /v1.0. That's basically all we need to do. So let's move over to the ID. Before we can use the versioning NuGet package, we have to quickly configure it. And we do this right after the AddControllers call here in Program.cs. So we do builder.Services and then…
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.