Http.Client.Options
6.0.1
.NET 5.0
This package targets .NET 5.0. The package is compatible with this framework or higher.
.NET Standard 2.0
This package targets .NET Standard 2.0. The package is compatible with this framework or higher.
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package Http.Client.Options --version 6.0.1
NuGet\Install-Package Http.Client.Options -Version 6.0.1
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Http.Client.Options" Version="6.0.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Http.Client.Options --version 6.0.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Http.Client.Options, 6.0.1"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Http.Client.Options as a Cake Addin #addin nuget:?package=Http.Client.Options&version=6.0.1 // Install Http.Client.Options as a Cake Tool #tool nuget:?package=Http.Client.Options&version=6.0.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Purpurse
Simplefied usage of http client factory using Options pattern
Configuration options
All configuration are disabled by default
Connection
Http client base url properties
option | value |
---|---|
server | The domain name of the base url |
port | The port part of the base url |
schema | The schema part of the base url (http/ https) |
timeout | Connection timeout, will be set as http client timeout |
serviceCollection.AddHttpClientOptions(options =>
{
options.ServiceName = "jsonplaceholder";
options.ConnectionOptions.Server = "jsonplaceholder.typicode.com";
options.ConnectionOptions.Schema = "http";
options.ConnectionOptions.Port = 80;
options.ConnectionOptions.Timeout = Timeout;
});
Http Client Handler
The http client heandler properties
option | value |
---|---|
MaxConnection | The maximum number of concurrent connections (per server endpoint) |
HandlerLifeTimeMinutes | The length of time that a HttpMessageHandler instance can be reused |
serviceCollection.AddHttpClientOptions(options =>
{
options.ServiceName = "my-service";
options.HttpClientHandlerOptions.MaxConnection = 1;
options.HttpClientHandlerOptions.HandlerLifeTimeMinutes = 10;
});
Telemetry
Enable or disable metrix options
option | value |
---|---|
Counter | Enable count of total requests, active request, sucesses,and errors |
Timing | Enable timing of the http requests |
serviceCollection.AddHttpClientOptions(options =>
{
options.ServiceName = "service";
options.TelemetryOptions.Counter = true;
options.TelemetryOptions.Timing = true;
});
Polly Options
All policies are disabled by default
Bulkhead
serviceCollection.AddHttpClientOptions(options =>
{
options.ServiceName = "service";
options.PollyOptions.Bulkhead.Enabled = true;
options.PollyOptions.Bulkhead.MaxParallelization = 100;
options.PollyOptions.Bulkhead.MaxQueuingActions = 10000;
});
Retry
serviceCollection.AddHttpClientOptions(options =>
{
options.ServiceName = "service";
options.PollyOptions.Retry.Enabled = true;
options.PollyOptions.Retry.Count = 5;
options.PollyOptions.Retry.BackoffPower = 3;
options.PollyOptions.Retry.MaxJitter = 100;
});
CircuitBreaker
serviceCollection.AddHttpClientOptions(options =>
{
options.ServiceName = "service";
options.PollyOptions.CircuitBreaker.Enabled = true;
options.PollyOptions.CircuitBreaker.FailureThreshold = 0.7;
options.PollyOptions.CircuitBreaker.MinimumThroughput = 20;
options.PollyOptions.CircuitBreaker.SamplingDuration = 1000;
});
Timeout
serviceCollection.AddHttpClientOptions(options =>
{
options.ServiceName = "service";
options.PollyOptions.Timeout.Enabled = true;
options.PollyOptions.Timeout.TimeoutMS = 1000;
});
Binding Options
Bind http Client by type
serviceCollection.AddHttpClientOptions<ServiceClient>(options =>
{
options.ServiceName = "service";
options.TelemetryOptions.Counter = true;
options.TelemetryOptions.Timing = true;
});
Usage of named client
var factory = serviceProvider.GetRequiredService<IHttpClientFactory>();
var client = factory.CreateClient("service");
await client.GetAsync("todos/1");
Usage of typed client
class ServiceClient
{
private readonly HttpClient _httpClient;
public ServiceClient(HttpClient httpClient)
{
_httpClient = httpClient;
}
public Task<HttpResponseMessage> Get()
{
return _httpClient.GetAsync("todos/1");
}
}
Runtime configuration source
serviceCollection.AddHttpClientOptions(options =>
{
options.ServiceName = "service";
options.ConnectionOptions.Provider = () => new HttpConnectionOptions()
{
Server = ExternalProvider.Get<HttpServiceProps>().Domain
};
options.PollyOptions.Provider = () => new HttpPollyOptions()
{
Retry = ExternalProvider.Get<HttpServiceProps>().Retry
};
options.HttpClientHandlerOptions.Provider = () => new HttpClientHandlerOptions()
{
MaxConnection = ExternalProvider.Get<HttpServiceProps>().MaxConnection
};
});
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 is compatible. net5.0-windows was computed. net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 is compatible. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
.NETStandard 2.0
- Microsoft.ApplicationInsights (>= 2.17.0)
- Microsoft.Extensions.Http (>= 3.1.22)
- Microsoft.Extensions.Http.Polly (>= 3.1.22)
- OpenTelemetry (>= 1.0.1)
- OpenTelemetry.Extensions.Hosting (>= 1.0.0-rc2)
- OpenTelemetry.Instrumentation.Http (>= 1.0.0-rc2)
- Polly (>= 7.2.3)
- Polly.Extensions.Http (>= 3.0.0)
- System.ComponentModel.Annotations (>= 4.7.0)
- System.Diagnostics.Tracing (>= 4.3.0)
-
.NETStandard 2.1
- Microsoft.ApplicationInsights (>= 2.17.0)
- Microsoft.Extensions.Http (>= 3.1.22)
- Microsoft.Extensions.Http.Polly (>= 3.1.22)
- OpenTelemetry (>= 1.0.1)
- OpenTelemetry.Extensions.Hosting (>= 1.0.0-rc2)
- OpenTelemetry.Instrumentation.Http (>= 1.0.0-rc2)
- Polly (>= 7.2.3)
- Polly.Extensions.Http (>= 3.0.0)
- System.ComponentModel.Annotations (>= 4.7.0)
- System.Diagnostics.Tracing (>= 4.3.0)
-
net5.0
- Microsoft.ApplicationInsights (>= 2.17.0)
- Microsoft.Extensions.Http (>= 3.1.22)
- Microsoft.Extensions.Http.Polly (>= 3.1.22)
- OpenTelemetry (>= 1.0.1)
- OpenTelemetry.Extensions.Hosting (>= 1.0.0-rc2)
- OpenTelemetry.Instrumentation.Http (>= 1.0.0-rc2)
- Polly (>= 7.2.3)
- Polly.Extensions.Http (>= 3.0.0)
- System.ComponentModel.Annotations (>= 4.7.0)
- System.Diagnostics.Tracing (>= 4.3.0)
-
net6.0
- Microsoft.ApplicationInsights (>= 2.17.0)
- Microsoft.Extensions.Http (>= 3.1.22)
- Microsoft.Extensions.Http.Polly (>= 3.1.22)
- OpenTelemetry (>= 1.0.1)
- OpenTelemetry.Extensions.Hosting (>= 1.0.0-rc2)
- OpenTelemetry.Instrumentation.Http (>= 1.0.0-rc2)
- Polly (>= 7.2.3)
- Polly.Extensions.Http (>= 3.0.0)
- System.ComponentModel.Annotations (>= 4.7.0)
- System.Diagnostics.Tracing (>= 4.3.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
8.0.0-beta.63 | 112 | 4/12/2023 |
8.0.0-beta.62 | 87 | 4/12/2023 |
8.0.0-beta.61 | 70 | 4/12/2023 |
8.0.0-beta.60 | 75 | 4/12/2023 |
8.0.0-beta.57 | 76 | 4/12/2023 |
8.0.0-beta.20 | 74 | 4/13/2023 |
8.0.0-beta.18 | 76 | 4/13/2023 |
8.0.0-beta.17 | 73 | 4/13/2023 |
8.0.0-beta.10 | 72 | 4/12/2023 |
8.0.0-beta.9 | 74 | 4/12/2023 |
8.0.0-beta.1 | 84 | 3/13/2023 |
8.0.0-alpha.10 | 70 | 4/13/2023 |
7.2.3-alpha | 118 | 11/4/2022 |
7.2.2-alpha | 99 | 11/3/2022 |
7.2.1-alpha | 103 | 11/3/2022 |
7.2.0 | 21,587 | 4/27/2022 |
7.2.0-alpha | 94 | 11/3/2022 |
7.1.0 | 129 | 4/25/2022 |
7.0.1 | 128 | 4/25/2022 |
6.0.1 | 14,181 | 2/21/2022 |
6.0.0.4 | 4,879 | 1/3/2022 |
6.0.0.3 | 282 | 1/3/2022 |
6.0.0.2 | 276 | 1/3/2022 |
6.0.0.1 | 10,994 | 11/10/2021 |
5.0.6 | 323 | 11/10/2021 |
5.0.0.2 | 313 | 11/10/2021 |
5.0.0.1 | 334 | 11/10/2021 |
5.0.0.1-preview | 232 | 11/10/2021 |