Wiaoj.Resilience.Http 0.5.1-alpha

This is a prerelease version of Wiaoj.Resilience.Http.
dotnet add package Wiaoj.Resilience.Http --version 0.5.1-alpha
                    
NuGet\Install-Package Wiaoj.Resilience.Http -Version 0.5.1-alpha
                    
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="Wiaoj.Resilience.Http" Version="0.5.1-alpha" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Wiaoj.Resilience.Http" Version="0.5.1-alpha" />
                    
Directory.Packages.props
<PackageReference Include="Wiaoj.Resilience.Http" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Wiaoj.Resilience.Http --version 0.5.1-alpha
                    
#r "nuget: Wiaoj.Resilience.Http, 0.5.1-alpha"
                    
#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.
#:package Wiaoj.Resilience.Http@0.5.1-alpha
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Wiaoj.Resilience.Http&version=0.5.1-alpha&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=Wiaoj.Resilience.Http&version=0.5.1-alpha&prerelease
                    
Install as a Cake Tool

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.

Wiaoj.Http interprets Retry-After. This package still owns retry eligibility, backoff and the maximum delay: a usable server hint is a minimum wait, and a hint beyond the configured maximum prevents the retry.

Product Compatible and additional computed target framework versions.
.NET net11.0 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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