Microsoft.Extensions.Http 10.0.0-preview.2.25163.2
About
Microsoft.Extensions.Http package provides AddHttpClient extension methods for IServiceCollection, IHttpClientFactory interface and its default implementation. This provides the ability to set up named HttpClient configurations in a DI container and later retrieve them via an injected IHttpClientFactory instance.
Key Features
- The package allows to fluently set up multiple
HttpClientconfigurations for applications that use DI viaAddHttpClientextension method. HttpClientFactorycachesHttpMessageHandlerinstances per configuration name, which allows to reuse resources betweenHttpClientinstances to avoid port exhaustion.HttpClientFactorymanages lifetime ofHttpMessageHandlerinstances and recycles connections to track DNS changes.
How to Use
Note that lifetime management of HttpClient instances created by HttpClientFactory is completely different from instances created manually. The strategies are to use either short-lived clients created by HttpClientFactory or long-lived clients with PooledConnectionLifetime set up. For more information, see the HttpClient lifetime management section in the conceptual docs and Guidelines for using HTTP clients.
Configuring HttpClient
builder.Services.AddHttpClient("foo"); // adding an HttpClient named "foo" with a default configuration
builder.Services.AddHttpClient("example", c => c.BaseAddress = new Uri("https://www.example.com")) // configuring HttpClient itself
.AddHttpMessageHandler<MyAuthHandler>() // adding additional delegating handlers to form a message handler chain
.ConfigurePrimaryHttpMessageHandler(b => new HttpClientHandler() { AllowAutoRedirect = false }) // configuring primary handler
.SetHandlerLifetime(TimeSpan.FromMinutes(30)); // changing the handler recycling interval
Using the configured HttpClient
public class MyService
{
public MyService(IHttpClientFactory httpClientFactory)
{
_httpClientFactory = httpClientFactory; // injecting the factory
}
private Task<string> GetExampleAsync(Uri uri, CancellationToken ct)
{
HttpClient exampleClient = _httpClientFactory.CreateClient("example"); // creating the client for the specified name
return exampleClient.GetStringAsync(uri, ct); // using the client
}
}
Main Types
The main types provided by this library are:
IHttpClientFactoryIHttpMessageHandlerFactoryHttpClientFactoryServiceCollectionExtensions
Additional Documentation
- Conceptual documentation
- Also see HttpClient guidelines conceptual doc
- API documentation
- Also see
AddHttpClientextension method API doc
- Also see
Related Packages
- Microsoft.Extensions.DependencyInjection
- Microsoft.Extensions.Http.Polly
- Microsoft.Extensions.Http.Telemetry
Feedback & Contributing
Microsoft.Extensions.Http is released as open source under the MIT license. Bug reports and contributions are welcome at the GitHub repository.
Showing the top 20 packages that depend on Microsoft.Extensions.Http.
| Packages | Downloads |
|---|---|
|
Microsoft.Extensions.Http.Diagnostics
Telemetry support for HTTP Client.
|
4 |
|
Duende.AccessTokenManagement
Automatic access token management for OAuth client credential flows
|
3 |
|
Microsoft.Extensions.Http.Polly
The HttpClient factory is a pattern for configuring and retrieving named HttpClients in a composable way. This package integrates IHttpClientFactory with the Polly library, to add transient-fault-handling and resiliency through fluent policies such as Retry, Circuit Breaker, Timeout, Bulkhead Isolation, and Fallback.
This package was built from the source code at https://github.com/dotnet/aspnetcore/tree/cb14812a5c6098bd1091f5b7fd471ce2be45e8dd
|
3 |
|
payOS
payOS .NET SDK for convenient access to the payOS Merchant API.
|
3 |
|
Microsoft.Extensions.Http.Polly
The HttpClient factory is a pattern for configuring and retrieving named HttpClients in a composable way. This package integrates IHttpClientFactory with the Polly library, to add transient-fault-handling and resiliency through fluent policies such as Retry, Circuit Breaker, Timeout, Bulkhead Isolation, and Fallback.
|
3 |
|
Grpc.Net.ClientFactory
HttpClientFactory integration the for gRPC .NET client
|
3 |
|
Microsoft.Extensions.Http.Diagnostics
Telemetry support for HTTP Client.
|
3 |
|
Microsoft.OData.Client
LINQ-enabled client API for issuing OData queries and consuming OData JSON payloads. Supports OData v4 and v4.01. Targets .NET 8 or above.
OData .NET library is open source at http://github.com/OData/odata.net. Documentation for the library can be found at https://docs.microsoft.com/en-us/odata/.
|
2 |
|
Microsoft.Extensions.Http.Polly
The HttpClient factory is a pattern for configuring and retrieving named HttpClients in a composable way. This package integrates IHttpClientFactory with the Polly library, to add transient-fault-handling and resiliency through fluent policies such as Retry, Circuit Breaker, Timeout, Bulkhead Isolation, and Fallback.
|
2 |
|
Microsoft.Extensions.Http.Polly
The HttpClient factory is a pattern for configuring and retrieving named HttpClients in a composable way. This package integrates IHttpClientFactory with the Polly library, to add transient-fault-handling and resiliency through fluent policies such as Retry, Circuit Breaker, Timeout, Bulkhead Isolation, and Fallback.
This package was built from the source code at https://github.com/dotnet/aspnetcore/tree/b8139c5ee58f1708b0e3368a1b241400edd6cbc4
|
2 |
|
Microsoft.Extensions.Http.Polly
The HttpClient factory is a pattern for configuring and retrieving named HttpClients in a composable way. This package integrates IHttpClientFactory with the Polly library, to add transient-fault-handling and resiliency through fluent policies such as Retry, Circuit Breaker, Timeout, Bulkhead Isolation, and Fallback.
This package was built from the source code at https://github.com/dotnet/aspnetcore/tree/773e8cc3fbdc2c4ffbd57c1f53f21649ef94c35c
|
2 |
|
Microsoft.OData.Client
LINQ-enabled client API for issuing OData queries and consuming OData JSON payloads. Supports OData v4. Targets .NET 4.5 and .NET Platform Standard 1.1.
OData .NET library is open source at http://github.com/OData/odata.net. Documentation for the library can be found at https://docs.microsoft.com/en-us/odata/.
|
2 |
|
Microsoft.Extensions.Http.Polly
The HttpClient factory is a pattern for configuring and retrieving named HttpClients in a composable way. This package integrates IHttpClientFactory with the Polly library, to add transient-fault-handling and resiliency through fluent policies such as Retry, Circuit Breaker, Timeout, Bulkhead Isolation, and Fallback.
This package was built from the source code at https://github.com/dotnet/aspnetcore/tree/1dcf7acfacf0fe154adcc23270cb0da11ff44ace
|
2 |
.NET Framework 4.6.2
- Microsoft.Extensions.Configuration.Abstractions (>= 10.0.0-preview.2.25163.2)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.0-preview.2.25163.2)
- Microsoft.Extensions.Logging.Abstractions (>= 10.0.0-preview.2.25163.2)
- Microsoft.Extensions.Logging (>= 10.0.0-preview.2.25163.2)
- Microsoft.Extensions.Options (>= 10.0.0-preview.2.25163.2)
.NET 8.0
- Microsoft.Extensions.Configuration.Abstractions (>= 10.0.0-preview.2.25163.2)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.0-preview.2.25163.2)
- Microsoft.Extensions.Diagnostics (>= 10.0.0-preview.2.25163.2)
- Microsoft.Extensions.Logging.Abstractions (>= 10.0.0-preview.2.25163.2)
- Microsoft.Extensions.Logging (>= 10.0.0-preview.2.25163.2)
- Microsoft.Extensions.Options (>= 10.0.0-preview.2.25163.2)
.NET 9.0
- Microsoft.Extensions.Configuration.Abstractions (>= 10.0.0-preview.2.25163.2)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.0-preview.2.25163.2)
- Microsoft.Extensions.Diagnostics (>= 10.0.0-preview.2.25163.2)
- Microsoft.Extensions.Logging.Abstractions (>= 10.0.0-preview.2.25163.2)
- Microsoft.Extensions.Logging (>= 10.0.0-preview.2.25163.2)
- Microsoft.Extensions.Options (>= 10.0.0-preview.2.25163.2)
.NET 10.0
- Microsoft.Extensions.Configuration.Abstractions (>= 10.0.0-preview.2.25163.2)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.0-preview.2.25163.2)
- Microsoft.Extensions.Diagnostics (>= 10.0.0-preview.2.25163.2)
- Microsoft.Extensions.Logging.Abstractions (>= 10.0.0-preview.2.25163.2)
- Microsoft.Extensions.Logging (>= 10.0.0-preview.2.25163.2)
- Microsoft.Extensions.Options (>= 10.0.0-preview.2.25163.2)
.NET Standard 2.0
- Microsoft.Extensions.Configuration.Abstractions (>= 10.0.0-preview.2.25163.2)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.0-preview.2.25163.2)
- Microsoft.Extensions.Logging.Abstractions (>= 10.0.0-preview.2.25163.2)
- Microsoft.Extensions.Logging (>= 10.0.0-preview.2.25163.2)
- Microsoft.Extensions.Options (>= 10.0.0-preview.2.25163.2)