-
Notifications
You must be signed in to change notification settings - Fork 711
API Version Reader
The IApiVersionReader interface defines the behavior of how an API version is read in its raw, unparsed form from the current HTTP request. There are three methods for reading an API version provided out-of-the-box or you can implement your own. The default, configured API version reader is an instance of the QueryStringApiVersionReader class.
ASP.NET Web API
public interface IApiVersionReader
{
string Read( HttpRequestMessage request );
}
ASP.NET Core
public interface IApiVersionReader
{
string Read( HttpRequest request );
}
The QueryStringApiVersionReader reads the requested API version from the requested query string. The default query string parameter name is api-version. The constructor for this class accepts the name of a query string parameter so that an alternate query string parameter can be used.
services.AddApiVersioning(
o => o.ApiVersionReader =
new QueryStringApiVersionReader( "version" ) );
The HeaderApiVersionReader reads the requested API version from a HTTP request header. There is no default or standard HTTP header. You must define which HTTP header name or names contain the API version information. This method of API versioning does not conform to the Microsoft REST Guidelines.
services.AddApiVersioning(
o => o.ApiVersionReader =
new HeaderApiVersionReader( "api-version" ) );
The QueryStringOrHeaderApiVersionReader reads the requested API version from the requested query string or a HTTP header. A value specified in the query string parameter takes precedence over a HTTP header. This implementation is useful for existing services that support API versioning, but are not compliant with the Microsoft REST Guidelines. The default query string parameter name is api-version. The constructor for this class accepts the name of a query string parameter so that an alternate query string parameter can be used. No HTTP headers are defined by default.
services.AddApiVersioning(
o => o.ApiVersionReader =
new QueryStringOrHeaderApiVersionReader()
{
Headers = { "x-ms-version" }
} );
- Home
- Quick Starts
- Version Format
- Version Discovery
- Version Policies
- How to Version Your Service
- API Versioning with OData
- Configuring Your Application
- Error Responses
- API Documentation
- Extensions and Customizations
- Known Limitations
- FAQ
- Examples