From the course: Building and Securing RESTful APIs in ASP.NET Core

Unlock the full course today

Join today to access over 22,500 courses taught by industry experts or purchase this course individually.

Add versioning support

Add versioning support - ASP.NET Core Tutorial

From the course: Building and Securing RESTful APIs in ASP.NET Core

Start my 1-month free trial

Add versioning support

- [Instructor] To add versioning to this API, we need to add a new package. So we'll start in the package manager. I'm gonna search for the Microsoft.AspNetCore.Mvc.Versioning package and go ahead and install this. This package is flexible enough to support URL versioning, header or media type versioning, as well as other styles. Once the package is installed, I'll go to the startup class to configure it. We'll do this configuration in the configure services method. I'll do services.AddApiVersioning and pass some options. First I wanna say that if I don't specify an API version, just assume the default version is new ApiVersion 1.0. I also need to specify where to find API version information, where to read it from. So I'll say options.ApiVersionReader equals new, we want the MediaTypeApiVersionReader. Import this namespace from versioning. Next I wanna tell it that if I don't specify an API version, I want to assume the default version to be the one I specified earlier, 1.0. I want…

Contents