From the course: Advanced Web APIs with ASP.NET Core 8

Unlock the full course today

Join today to access over 24,700 courses taught by industry experts.

Using the Accept header for versioning

Using the Accept header for versioning - ASP.NET Core Tutorial

From the course: Advanced Web APIs with ASP.NET Core 8

Using the Accept header for versioning

- [Instructor] I already mentioned that we could also use the Accept HTTP header for version information and I'd like to show you now how this could be done. And this also allows me to introduce another feature I already briefly mentioned. We can have different ApiVersionReaders and this is how this works. We can use a static method called ApiVersionReader.Combine, which combines several ApiVersionReaders and they will be used one after the other. And as soon as one of those readers returns an API version, ASP.NET Core stops and is using that version number or version identifier. I would like to keep the header ApiVersionReader, but I'd like to use a second one, the MediaTypeApiVersionReader because when we use the Accept HTTP header, we are providing the MediaType we accept in that API call as the data being returned. In that Accept header, we usually have something like */* or application/json and then we can append the version information. We have to tell ASP.NET Core how we are…

Contents