A lot has been written about API versioning and the opinions differ on what the 'best' approach is.
I'm not planning to add an extra opinion to the mix, instead I want to focus on one of the ways you can do API versioning in ASP.NET Core.
Versioning by content type
When using versioning by content type, we use custom media types instead of generic types such as application/json. To make this work we can rely on content negotiation inside our API.
Here is an example:
Accept: application/vnd.example.v1+json
Accept: application/vnd.example+json;version=1.0
Inside our ASP.NET Core controllers, we have to introduce the [Consumes]
attribute. This attribute allows an action to influence its selection based on an incoming request's content type by applying a type constraint.
What about Minimal API’s?
At the moment of writing, ASP.NET Core Minimal API’s don’t support content negotiation (yet).