-
Notifications
You must be signed in to change notification settings - Fork 225
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
[Feature Request] Allow configuration of HttpClients for IDownstreamWebApi #1740
Comments
Not sure if this helps, but this is what I´m doing to achieve what you need. Basically, I´m overwriting the HttpClient used by services
.AddHttpClient<IDownstreamWebApi, DownstreamWebApi>(client =>
{
client.DefaultRequestHeaders.Add("Accept", "application/json");
})
.AddMyPollyStuff(); |
I didn't think of that, looks like a good solution/workaround in scenarios where one policy is enough. In my case I call multiple downstream APIs, each with different needs, so I need to be able to specify a policy per API. |
We would really like this for our project too. |
It's coming in v2 with the new DownstreamRestApi interface |
done in 2.5.0. |
I recently ran into the very same problem of registering a Polly-based HTTP message handler for the underlying Just as a confirmation, is the suggested solution the one showed here by @h3rmanj ? If that is the case, it could be great to explain that in the library documentation. It seems it is not mentioned anywhere in the available documentation and examples for |
Can confirm, currently using this extension when registering our downstream clients. Works with both on-behalf-of and client credential scenarios. /// <summary>
/// Extension methods to support downstream web API services.
/// </summary>
public static class DownstreamApiExtensions
{
/// <summary>
/// Adds a named downstream web API service related to a specific configuration section.
/// </summary>
/// <param name="services">Services.</param>
/// <param name="serviceName">Name of the configuration for the service.
/// This is the name used when calling the service from controller/pages.</param>
/// <param name="configuration">Configuration.</param>
/// <returns>The httpClientBuilder for the client to use.</returns>
public static IHttpClientBuilder AddDownstreamApiClient(this IServiceCollection services,
string serviceName,
IConfiguration configuration)
{
services.AddDownstreamApi(serviceName, configuration);
return services.AddHttpClient(serviceName);
}
} Agree docs should be added for this. |
@h3rmanj many thanks for the confirmation. I will do the same for my project. Still wondering if this is the intended way to use the abstraction. This is working because the underlying If you want to be safer in terms of breaking changes, an alternative is manually getting an access token and then use it with an instance of |
Is your feature request related to a problem? Please describe.
I'd like to add Polly policies, described in these docs on how to implement resilient http requests.
However I can't really access the HttpClientBuilder when using the recommended way to call downstream apis.
There seems to be some incompatibility in whats recommended, and I'd like the gap to be closed.
Describe the solution you'd like
Some way to configure the HttpClients used by IDownstreamWebApi. I've proposed a solution in #1735 which allows the user to pass a
configureHttpClientBuilder
toAddDownstreamWebApi()
.Additional context
This was partly pointed out in #891 but wasn't really addressed when closed.
The text was updated successfully, but these errors were encountered: