microsoft-identity-web
microsoft-identity-web copied to clipboard
[Feature Request] Allow configuration of HttpClients for IDownstreamWebApi
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
to AddDownstreamWebApi()
.
Additional context This was partly pointed out in #891 but wasn't really addressed when closed.
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 AddDownstreamWebApi()
and then adding my Polly stuff in the HttpClientBuilder returned. In my case, it also helps to change some headers, as I´m calling SharePoint REST API, and returned XML by default
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 https://github.com/AzureAD/microsoft-identity-web/pull/1735#issuecomment-1308012205
done in 2.5.0.