<PackageReference Include="Microsoft.Extensions.Http" Version="11.0.0-preview.3.26207.106" />

Microsoft.Extensions.DependencyInjection.HttpClientBuilderExtensions

public static class HttpClientBuilderExtensions
Extension methods for configuring an IHttpClientBuilder.
public static IHttpClientBuilder AddAsKeyed(this IHttpClientBuilder builder, ServiceLifetime lifetime = 1)

Registers a named HttpClient and the related handler pipeline HttpMessageHandler as keyed services with the client's name as the key, and a lifetime provided in the lifetime parameter. By default, the lifetime is Scoped.

Adds back the default logging for a named HttpClient, if it was removed previously by calling RemoveAllLoggers.

public static IHttpClientBuilder AddHttpMessageHandler(this IHttpClientBuilder builder, Func<DelegatingHandler> configureHandler)

Adds a delegate that will be used to create an additional message handler for a named HttpClient.

Adds a delegate that will be used to create an additional message handler for a named HttpClient.

public static IHttpClientBuilder AddHttpMessageHandler<THandler>(this IHttpClientBuilder builder) where THandler : DelegatingHandler

Adds an additional message handler from the dependency injection container for a named HttpClient.

public static IHttpClientBuilder AddLogger(this IHttpClientBuilder builder, Func<IServiceProvider, IHttpClientLogger> httpClientLoggerFactory, bool wrapHandlersPipeline = false)

Adds a delegate that will be used to create an additional logger for a named HttpClient. The custom logger would be invoked from a dedicated logging DelegatingHandler on every request of the corresponding named HttpClient.

public static IHttpClientBuilder AddLogger<TLogger>(this IHttpClientBuilder builder, bool wrapHandlersPipeline = false) where TLogger : IHttpClientLogger

Adds a delegate that will be used to create an additional logger for a named HttpClient. The custom logger would be invoked from a dedicated logging DelegatingHandler on every request of the corresponding named HttpClient.

public static IHttpClientBuilder AddTypedClient<TClient>(this IHttpClientBuilder builder)

Configures a binding between the TClient type and the named HttpClient associated with the IHttpClientBuilder.

public static IHttpClientBuilder AddTypedClient<TClient, TImplementation>(this IHttpClientBuilder builder) where TImplementation : TClient

Configures a binding between the TClient type and the named HttpClient associated with the IHttpClientBuilder. The created instances will be of type TImplementation.

public static IHttpClientBuilder AddTypedClient<TClient>(this IHttpClientBuilder builder, Func<HttpClient, TClient> factory)

Configures a binding between the TClient type and the named HttpClient associated with the IHttpClientBuilder.

public static IHttpClientBuilder AddTypedClient<TClient>(this IHttpClientBuilder builder, Func<HttpClient, IServiceProvider, TClient> factory)

Configures a binding between the TClient type and the named HttpClient associated with the IHttpClientBuilder.

Adds a delegate that will be used to configure additional message handlers using HttpMessageHandlerBuilder for a named HttpClient.

public static IHttpClientBuilder ConfigureHttpClient(this IHttpClientBuilder builder, Action<HttpClient> configureClient)

Adds a delegate that will be used to configure a named HttpClient.

Adds a delegate that will be used to configure a named HttpClient.

Adds a delegate that will be used to configure message handlers using HttpMessageHandlerBuilder for a named HttpClient.

Adds a delegate that will be used to configure the primary HttpMessageHandler for a named HttpClient.

Adds a delegate that will be used to configure the primary HttpMessageHandler for a named HttpClient.

public static IHttpClientBuilder ConfigurePrimaryHttpMessageHandler<THandler>(this IHttpClientBuilder builder) where THandler : HttpMessageHandler

Configures the primary HttpMessageHandler from the dependency injection container for a named HttpClient.

Adds a delegate that will be used to configure the primary HttpMessageHandler for a named HttpClient.

public static IHttpClientBuilder RedactLoggedHeaders(this IHttpClientBuilder builder, Func<string, bool> shouldRedactHeaderValue)

Sets the Func<T, U> which determines whether to redact the HTTP header value given its corresponding header name before logging.

public static IHttpClientBuilder RedactLoggedHeaders(this IHttpClientBuilder builder, IEnumerable<string> redactedLoggedHeaderNames)

Sets the collection of HTTP headers names for which values should be redacted before logging.

Removes all previously added loggers for a named HttpClient, including default ones.

Removes the keyed registrations for the named HttpClient and HttpMessageHandler.

public static IHttpClientBuilder SetHandlerLifetime(this IHttpClientBuilder builder, TimeSpan handlerLifetime)

Sets the length of time that a HttpMessageHandler instance can be reused. Each named client can have its own configured handler lifetime value. The default value is two minutes. Set the lifetime to InfiniteTimeSpan to disable handler expiry.