4
votes

I have enabled versioning for Azure API Management (APIM). The versioning is based on querystring parameters (e.g. ?api-version=1.0). The intent for using a querystring is so that if the user doesn't provide the parameter, it'll default to the latest version. So:

/api/operation?api-version=1.0 <- Goes to 1.0
/api/operation?api-version=1.1 <- Goes to 1.1
/api/operation                 <- Goes to 1.1 (assuming that is latest)

However, it appears as though APIM uses that parameter as an indexer and if it's not provided, APIM doesn't know which version to use. Is there a way to tell APIM that, if the parameter is missing, automatically go to a specific version?

2

2 Answers

3
votes

Not possible in Azure APIM. API version is required to be passed for every request.

0
votes

Once you opt into API versioning, all API routes are explicitly versioned. This means a client cannot request a resource without explicitly providing an API version.

In order to make your scenario work, you need to allow match a default API version when a client doesn't specify anything. You could set up like below:

service.AddApiVersioning( options => options.AssumeDefaultVersionWhenUnspecified = true );

The AssumeDefaultVersionWhenUnspecified option enables support for clients to make requests with implicit API versioning. This option is disabled by default, which means that all clients must send requests with an explicit API version. Services will respond to client requests that do not specify an API version with either HTTP status code 400 (Bad Request) or HTTP status code 404 (Not Found), depending whether the requested route exists.

Also, you could use DefaultApiVersion option which defines what the default ApiVersion will be for a service without explicit API version information. The default configured value is 1.0.

services.AddApiVersioning(
    o => o.DefaultApiVersion =
        new ApiVersion( new DateTime( 2016, 7, 1 ) );

For more details, you could refer to this article.