Versioning of your API’s in ASP.NET Core is easy thanks to the Microsoft.Aspnetcore.Mvc.Versioning nuget package. It allows us to implement versioning with a few configuration lines.
After installing the Nuget you should update the ConfigureServices() method in Startup.cs:
Now you can add the [ApiVersion] attribute on your controller:
If you now have multiple versions of your api, you can decide which version to use by adding an ?api-version=1.0
at the end of your url.
So far nothing new. A feature I only discovered recently is that you can also flag an API as deprecated. Therefore you need to set an additional Deprecated property on the attribute:
When a client now calls the deprecated API, an extra response header ‘api-deprecated-versions’ is returned:
api-deprecated-versions: 1.0