CircuitBreaker.Http.Dispatcher 0.5.1

dotnet add package CircuitBreaker.Http.Dispatcher --version 0.5.1
                    
NuGet\Install-Package CircuitBreaker.Http.Dispatcher -Version 0.5.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="CircuitBreaker.Http.Dispatcher" Version="0.5.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="CircuitBreaker.Http.Dispatcher" Version="0.5.1" />
                    
Directory.Packages.props
<PackageReference Include="CircuitBreaker.Http.Dispatcher" />
                    
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 CircuitBreaker.Http.Dispatcher --version 0.5.1
                    
#r "nuget: CircuitBreaker.Http.Dispatcher, 0.5.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.
#:package CircuitBreaker.Http.Dispatcher@0.5.1
                    
#: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=CircuitBreaker.Http.Dispatcher&version=0.5.1
                    
Install as a Cake Addin
#tool nuget:?package=CircuitBreaker.Http.Dispatcher&version=0.5.1
                    
Install as a Cake Tool

CircuitBreaker.Http.Dispatcher

Part of the CircuitBreaker resilience ecosystem.

A lightweight, pipeline-friendly DelegatingHandler that routes HTTP responses to the right handler based on their status code, using a three-level priority chain:

Exact code (e.g. 429)  →  Family (e.g. 4xx)  →  Default

Installation

dotnet add package CircuitBreaker.Http.Dispatcher

Quick Start

using CircuitBreaker.Http.Dispatcher;
using System.Net;

var dispatcher = new StatusDispatchBuilder()
    // Handle 202 Accepted with automatic Location polling
    .OnStatus(HttpStatusCode.Accepted, new AcceptedPollingHandler())

    // Throw on rate limiting
    .OnStatus(HttpStatusCode.TooManyRequests, ctx =>
        throw new HttpRequestException($"Rate limited — retry after {ctx.Headers.RetryAfter}"))

    // Surface all 4xx as exceptions
    .OnFamily(HttpFamily.ClientError, ctx =>
        throw new HttpRequestException($"Client error: {(int)ctx.StatusCode} {ctx.StatusCode}"))

    // Log everything else, return response unchanged
    .OnDefault(ctx =>
    {
        Console.WriteLine($"[{ctx.StatusCode}] {ctx.Request.RequestUri}");
        return Task.FromResult(ctx.Response);
    })
    .Build(new HttpClientHandler());

var httpClient = new HttpClient(dispatcher)
{
    BaseAddress = new Uri("https://api.example.com")
};

HttpClientFactory Integration (ASP.NET Core)

builder.Services.AddHttpClient("MyClient")
    .AddHttpMessageHandler(sp =>
        new StatusDispatchBuilder()
            .OnStatus(HttpStatusCode.Accepted, new AcceptedPollingHandler())
            .OnFamily(HttpFamily.ServerError, ctx =>
                throw new HttpRequestException($"Server error: {ctx.StatusCode}"))
            .Build(new HttpClientHandler()));

Dispatch Priority

Priority Match Example
1 (highest) Exact status code OnStatus(429, ...)
2 HTTP family (1xx–5xx) OnFamily(ClientError, ...)
3 (lowest) Default catch-all OnDefault(...)
— No match Response returned unmodified

HttpStatusContext

Each handler receives an HttpStatusContext with:

Property Description
Request The original HttpRequestMessage
Response The HttpResponseMessage received
StatusCode Shortcut to Response.StatusCode
Headers Shortcut to Response.Headers
CancellationToken Pipeline cancellation token
Attempt Retry attempt number (1-based, enriched by Polly)
Elapsed Total elapsed time across retries
CorrelationId Optional trace/correlation identifier

AcceptedPollingHandler

A ready-to-use handler for the HTTP 202 + Location polling pattern:

var pollingHandler = new AcceptedPollingHandler(
    pollingClient: myHttpClient,        // optional, defaults to new HttpClient()
    pollInterval: TimeSpan.FromSeconds(2),
    isCompleted: r => r.StatusCode == HttpStatusCode.OK);

License

MIT — © 2026 Alessandro Silveira

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  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.  net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  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. 
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 141 7/20/2026