Wiaoj.Resilience.Http
0.4.2-alpha.2
See the version list below for details.
dotnet add package Wiaoj.Resilience.Http --version 0.4.2-alpha.2
NuGet\Install-Package Wiaoj.Resilience.Http -Version 0.4.2-alpha.2
<PackageReference Include="Wiaoj.Resilience.Http" Version="0.4.2-alpha.2" />
<PackageVersion Include="Wiaoj.Resilience.Http" Version="0.4.2-alpha.2" />
<PackageReference Include="Wiaoj.Resilience.Http" />
paket add Wiaoj.Resilience.Http --version 0.4.2-alpha.2
#r "nuget: Wiaoj.Resilience.Http, 0.4.2-alpha.2"
#:package Wiaoj.Resilience.Http@0.4.2-alpha.2
#addin nuget:?package=Wiaoj.Resilience.Http&version=0.4.2-alpha.2&prerelease
#tool nuget:?package=Wiaoj.Resilience.Http&version=0.4.2-alpha.2&prerelease
Wiaoj.Resilience.Http
Add retry, timeout, and circuit breaker layers to an HttpClient registered with
IHttpClientFactory. The transport-neutral policies live in Wiaoj.Resilience;
this adapter adds HTTP status classification, Retry-After handling, and
request-content replay controls.
Installation
dotnet add package Wiaoj.Resilience.Http
Quick start
using Microsoft.Extensions.DependencyInjection;
using Wiaoj.Resilience.Http;
services.AddHttpClient("catalog", client => {
client.BaseAddress = new Uri("https://catalog.example/");
})
.AddWiaojRetryHandler(options => {
options.MaxRetryAttempts = 2;
options.DisableForUnsafeHttpMethods();
});
Resolve IHttpClientFactory and call CreateClient("catalog"). The same
extensions work on AddHttpClient<CatalogClient>() for a typed client.
Compose a pipeline
Layers wrap one another in registration order: the first is outermost. In the following configuration the 12-second deadline covers all attempts and retry delays; the 3-second deadline applies separately to each attempt.
services.AddHttpClient("catalog")
.AddWiaojResilienceHandler("catalog-read", pipeline => pipeline
.AddTimeout(TimeSpan.FromSeconds(12))
.AddRetry(options => {
options.MaxRetryAttempts = 2;
options.DisableForUnsafeHttpMethods();
})
.AddTimeout(TimeSpan.FromSeconds(3)));
HttpClient.Timeout still applies to the entire call. Keep it larger than the
pipeline deadline if you want the outer pipeline timeout to fire first. An
explicit caller cancellation stops retries rather than counting as an attempt
failure. Service-provider lookups happen when the factory builds the handler.
Retry rules
| Setting | Default behavior |
|---|---|
| Retry count | 3 retries after the initial attempt |
| Delay | Exponential backoff from 1 second with jitter, capped at 30 seconds |
| HTTP response | Retry 408, 429, and 5xx |
| Exception | Retry HTTP request errors, timeouts, and cancellation not caused by the caller; do not retry argument errors or an open circuit by default |
Retry-After |
Honor the server minimum; return the response without retrying if it exceeds MaxDelay |
| Request content | Do not buffer streaming request bodies unless explicitly enabled |
A repeatable request body does not make the server operation idempotent.
By default only GET, HEAD, and OPTIONS are eligible. Explicitly opt in to other requests with a narrowly scoped ShouldRetryRequest predicate. If you opt in
to streaming-body replay with BufferRequestContent, use MaxBufferSize to
bound memory use. For writes, only retry when the server can deduplicate requests
or you otherwise know the operation is safe to repeat.
OnRetry receives the failed response or exception and the chosen delay before
the next attempt. Read the response in the callback if needed; the handler
disposes intermediate failed responses after the callback returns. An exhausted
HTTP response is returned as-is; it is up to the caller to decide how to handle
the final status code.
Circuit breakers
Register the policies with AddWiaojResilience and choose a
Wiaoj.DistributedCounter backend to hold the breaker state. For example:
using Wiaoj.DistributedCounter;
using Wiaoj.Resilience;
services.AddDistributedCounter(counter => counter.UseInMemory());
services.AddWiaojResilience(resilience =>
resilience.AddConsecutiveBreaker("catalog-breaker", options => {
options.FailureThreshold = 5;
options.BreakDuration = TimeSpan.FromSeconds(30);
}));
services.AddHttpClient("catalog")
.AddWiaojResilienceHandler("catalog-read", pipeline => pipeline
.AddRetry(options => options.DisableForUnsafeHttpMethods())
.AddCircuitBreaker("catalog-breaker"));
Here each retry attempt goes through the breaker. Put the breaker outside retry
if it should see only the overall operation outcome. For multiple instances,
use a shared counter backend instead of the in-memory backend shown here.
The breaker treats 408, 429, and 5xx as failures by default. Use
HttpCircuitBreakerOptions.IsFailureResponse to classify statuses differently.
An open circuit rejects the attempt with CircuitBreakerOpenException; retry
does not retry that exception by default. Use the overload with an explicit
resilience key when different clients should not share breaker state.
Observability
Enable the Wiaoj.Resilience.Http meter and activity source in OpenTelemetry.
HTTP retry diagnostics include the attempt count, delay, HTTP status or exception
type, and the final outcome. Keep credentials out of paths and resilience keys.
See the core package documentation for timeout strategies, distributed circuit breakers, and non-HTTP retry pipelines.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- Microsoft.Extensions.Configuration (>= 10.0.11)
- Microsoft.Extensions.Configuration.Abstractions (>= 10.0.12)
- Microsoft.Extensions.DependencyInjection (>= 10.0.11)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.12)
- Microsoft.Extensions.Hosting.Abstractions (>= 10.0.12)
- Microsoft.Extensions.Http (>= 10.0.0)
- Microsoft.Extensions.Logging (>= 10.0.11)
- Microsoft.Extensions.Logging.Abstractions (>= 10.0.12)
- Microsoft.Extensions.Options (>= 10.0.12)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 10.0.11)
- Wiaoj.Preconditions (>= 0.4.2-alpha.2)
- Wiaoj.Resilience (>= 0.4.2-alpha.2)
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 |
|---|---|---|
| 0.5.1-alpha | 0 | 12/6/2026 |
| 0.5.0-alpha.1 | 0 | 12/5/2026 |
| 0.4.2-alpha.2 | 52 | 12/3/2026 |
| 0.4.2-alpha.1 | 55 | 12/2/2026 |