HTTP Client Configuration
Flux.REST allows configuring an HttpClient for each Flux Service registered with UsingRest. The URL passed to UsingRest becomes the client’s BaseAddress.
Use ConfigureHttpClient to apply additional HttpClient settings for that Flux Service.
services.AddFlux(flux =>
{
flux.AddService("example-api")
.UsingRest("https://api.example.com")
.ConfigureHttpClient((HttpClient client) =>
{
// Configure the HttpClient here
});
});
The configuration applies to requests made through every Set belonging to the "example-api" Flux Service.
Tip
See the
HttpClientAPI reference for the available configuration options.
ConfigureHttpClient also has an overload that provides IServiceProvider when the configuration requires a registered dependency:
services.AddFlux(flux =>
{
flux.AddService("example-api")
.UsingRest("https://api.example.com")
.ConfigureHttpClient((IServiceProvider serviceProvider, HttpClient client) =>
{
// Configure the HttpClient here
});
});