-
Notifications
You must be signed in to change notification settings - Fork 708
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
asynchronously defining api version #1009
Comments
Changing the signature or adding a new method to Fear not! There are other options. While
Consider the world's simplest middleware: app.Use((context, next) =>
{
var feature = context.ApiVersioningFeature();
if (feature.RawRequestedApiVersions.Count == 0 &&
context.Request.Headers.TryGetValue(HttpHeaders.From, out var from))
{
var version = await customers.GetDefaultApiVersion(from);
// this can also be RequestedApiVersion if the value is already parsed
feature.RawRequestedApiVersion = version;
}
return await next(context);
}); This is essentially what would happen later. Something to the effect of: if (feature.RawRequestedApiVersions.Count == 0 &&
options.AssumeDefaultVersionWhenUnspecified)
{
var model = AggregateApiVersionModelFromCandidates(candidates);
feature.RequestedApiVersion = selector.SelectApiVersion(context.Requested, model);
} In your case, you don't have to worry about Adding an async method isn't completely off the table, but I likely wouldn't add it until the next major version change. That would coincide with the .NET 8 release (~Nov). |
I'm currently considering whether to add this capability. Even as additive, it will technically be a breaking change. The support for default interface implementations will help reduce the impact. I'm thinking of something like: public interface IApiVersionSelector
{
ApiVersion SelectVersion( HttpRequest request, ApiVersionModel model );
ValueTask<ApiVersion> SelectVersionAsync(
HttpRequest request,
ApiVersionModel model,
CancellationToken cancellationToken ) =>
ValueTask.FromResult( SelectVersion( request, model ) );
} What I would like to understand better is what will happen when you cannot resolve anything from the Aside from just changing the signature, I wonder what the thoughts are of implementing two method variants of the interface are? All of the current implementations are synchronous and there are numerous scenarios where the current HTTP context may not be available. I'm debating refactoring the parameter to be nullable or provide a default, empty HTTP request. In either case, the request is useless for the purposes of resolving an API version. A clear and obvious use case for such a scenario would be in documentation (e.g. OpenAPI). The default version could vary by API, which can only be known through the What I would expect an implementer to do given no useful information in the HTTP request is one of the following:
The other downside of this approach is that there is no guarantee that this will always be the behavior. There could be a scenario where it logically makes sense or things are intrinsically synchronous. If the expected information is in the HTTP request, the this should result in a blocking call with I know there are people out there that have written custom |
|
hi,
would you mind making SelectVersion from the interface IApiVersionSelector async?
why?
well, we develop an ERP that releases 4 versions per year, for example 2023.1, 2023.2, 2023.3 and 2023.4.
we support the last 3 versions, so in this example would be 2023.2, 2023.3 and 2023.4
at the end of the day, we know in what version each of our customers are, by consuming an internal api
with that in mind, i would like to make an request to that internal api and fetch the correct version
only when no API version is especified
is that possible?
thank you
The text was updated successfully, but these errors were encountered: