Refit.HttpClientFactory 16.0.0

Prefix Reserved

Requires NuGet 2.12 or higher.

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

Refit

Refit

Build NuGet

Refit turns a C# interface into an HTTP client. Attributes describe the request method, URL, headers and body. The source generator builds its implementation when your app compiles. Your app keeps control of HttpClient, cancellation and serialization.

Start with the Refit documentation. It explains the concepts, walks through a first request, and links each topic to runnable source examples. Examples use .NET 10 and C# 14 unless they state another target. Website code blocks can show a subset of a complete example and omit its test setup.

Packages

Package Purpose
Refit Generated HTTP clients, request attributes, serializers and response types. Includes the generator, interface analyzers and code fixes.
Refit.HttpClientFactory Register clients with dependency injection and IHttpClientFactory, including generated-only and keyed registrations.
Refit.Testing Match outgoing requests, supply local replies, verify calls and simulate network faults.
Refit.Newtonsoft.Json Serialize content with Newtonsoft.Json.
Refit.Xml Serialize XML content.
Refit.Reflection Optional request building through runtime reflection. Use generated clients for trimmed and Native AOT apps.

System.Text.Json with generated metadata is the preferred JSON setup. See JSON configuration and AOT guidance.

What you can build

Surface Documentation
HTTP methods, route placeholders and request inspection Routes
Scalar, object and collection queries; formatting and converters Queries
Static and dynamic headers, authorization and request state Headers and request context
Serialized bodies, forms, buffering and request compression Bodies
Task<T>, ValueTask<T>, IObservable<T> and response wrappers Return types and responses
Streamed JSON arrays, JSON Lines and server-sent events Streaming
HTTP, transport and deserialization failures Errors
Local replies, request verification and simulated faults Testing

See why use Refit for equivalent manual HTTP code and trade-offs. The website records known behavior discrepancies beside the affected APIs.

Public API map

Use the full API reference to find types, overloads, parameters and return values across all topics on one page.

Public method group Brief description Documentation
HTTP verb and route attributes Declare the HTTP method, route template, base-path prefix and URL resolution behavior. Routes
Query attributes and formatters Add scalar, object, collection, flag, encoded, formatted and converted query values. Queries, formatters and converters
Headers, authorization and request context Add shared or per-call headers, obtain tokens and attach local handler state. Headers and request context
Bodies, forms, multipart and compression Serialize request bodies, send forms, files or streams, choose buffering and apply request compression. Bodies and multipart
Client creation and request builders Create generated or reflection clients, create owned HttpClient instances and supply request builders. Client creation and request builders
Settings and request metadata Configure serializers, formatters, exception factories, transport behavior, request options, timeouts, versions and URL resolution. Settings, metadata and helpers
Return types, responses and adapters Choose Task, ValueTask, IObservable<T>, IAsyncEnumerable<T>, response wrappers and custom return adapters. Return types, responses, streaming and adapters
Errors and problem details Read typed error content, create or transform API and transport exceptions, enforce success and redact sensitive details. Errors
Content serializers Use System.Text.Json, JSON Lines, synchronous or streaming serializer capabilities and custom serializers. JSON and content
Alternate serializers Configure Newtonsoft.Json and XML serializers with their settings. Newtonsoft.Json and XML
HTTP client factory and dependency injection Register generated, reflection or keyed clients, settings holders and authorization providers. Dependency injection
Testing routes, replies, faults and verification Match requests, create replies, inject failures or delays, inspect bodies and verify calls. Testing
Advanced generated request helpers Extend or inspect request construction through query builders, parameter providers and helper contracts. Query builder and request helpers

Build requirements and targets

The source generator requires Roslyn 4.8 or newer and PackageReference. .NET SDK 8.0.100 and Visual Studio 2022 17.8 provide that compiler baseline. These build requirements are separate from the application's target framework.

The source projects target .NET 8, 9, 10 and 11, plus .NET Framework 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8 and 4.8.1. Availability of individual framework features can differ. Read the AOT guide before choosing reflection-dependent APIs for a trimmed or native app.

Examples and changes

Build every complete documentation example from src:

dotnet build Refit.slnx -c Release

Each website page links to its own project under examples/Documentation/Pages. Run a page project, such as examples/Documentation/Pages/requests-routes/requests-routes.csproj, to check its local reply assertions without contacting a live service. The documentation examples README lists the source layout and independent projects.

See breaking changes, GitHub releases, and contributing.

Sponsors

JetBrains Claude

Refit is licensed under the MIT license.

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 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.  net11.0 is compatible. 
.NET Framework net462 is compatible.  net463 was computed.  net47 is compatible.  net471 is compatible.  net472 is compatible.  net48 is compatible.  net481 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (461)

Showing the top 5 NuGet packages that depend on Refit.HttpClientFactory:

Package Downloads
Chargily.EpayGateway.NET

C# .NET Library to use Chargily Epay Payment Gateway

Elsa.Api.Client

Provides HTTP clients for the Elsa Workflows REST API.

Kontent.Ai.Delivery

Kontent.ai Delivery SDK

Uno.Extensions.Http.Refit

HTTP Refit Extensions for registering Refit endpoints for Uno Platform, UWP and WinUI

Kontent.Ai.Management

Kontent.ai Management SDK

GitHub repositories (46)

Showing the top 20 popular GitHub repositories that depend on Refit.HttpClientFactory:

Repository Stars
App-vNext/Polly
Polly is a .NET resilience and transient-fault-handling library that allows developers to express policies such as Retry, Circuit Breaker, Timeout, Bulkhead Isolation, and Fallback in a fluent and thread-safe manner. From version 6.0.1, Polly targets .NET Standard 1.1 and 2.0+.
dotnet/AspNetCore.Docs
Documentation for ASP.NET Core
LykosAI/StabilityMatrix
Multi-Platform Package Manager for Stable Diffusion
elsa-workflows/elsa-core
The Workflow Engine for .NET
aspnetrun/run-aspnetcore-microservices
Microservices on .NET platforms used ASP.NET Web API, Docker, RabbitMQ, MassTransit, Grpc, Yarp API Gateway, PostgreSQL, Redis, SQLite, SqlServer, Marten, Entity Framework Core, CQRS, MediatR, DDD, Vertical and Clean Architecture implementation with using latest features of .NET 8 and C# 12
SciSharp/BotSharp
AI Multi-Agent Framework in .NET
ErsatzTV/legacy
Open-source platform that transforms your personal media library into live, custom TV channels.
JasperFx/wolverine
Supercharged .NET server side development!
dotnetcore/WebApiClient
A REST API library with better functionality, performance, and scalability than refit
recyclarr/recyclarr
Automatically sync TRaSH Guides to your Sonarr and Radarr instances
TheCodeTraveler/AsyncAwaitBestPractices
Extensions for System.Threading.Tasks.Task and System.Threading.Tasks.ValueTask
AlphaYu/adnc
A pragmatic .NET 8 framework for modular monoliths to evolve seamlessly into distributed microservices.
CodeMazeBlog/CodeMazeGuides
Source code for 800+ C# and .NET articles from code-maze.com. Every article is a runnable solution, most with tests.
VladislavAntonyuk/MauiSamples
.NET MAUI Samples
ntxinh/AspNetCore-DDD
Full ASP.NET Core 10.0 LTS application with DDD, CQRS and Event Sourcing
TheCodeTraveler/GitTrends
A iOS and Android app to monitor the Views, Clones and Star history of your GitHub repos
TeamWheelWizard/WheelWizard
WheelWizard, Retro Rewind Launcher
CommunityToolkit/Maui.Markup
The .NET MAUI Markup Community Toolkit is a community-created library that contains Fluent C# Extension Methods to easily create your User Interface in C#
foxminchan/BookWorm
The practical implementation of Aspire using Microservices, AI-Agents
netcorepal/netcorepal-cloud-framework
一个基于ASP.NET Core实现的整洁领域驱动设计落地战术框架。 A tactical framework for Clean Domain-Driven Design based on ASP.NET Core.
Version Downloads Last Updated
16.0.0 0 9/20/2026
15.2.0 342,851 8/18/2026
15.1.0 64,066 8/15/2026
15.0.0 146,936 8/5/2026
15.0.0-beta.1 157 8/3/2026
14.0.1 262,823 7/26/2026
14.0.0 12,200 7/25/2026
14.0.0-beta.5 182 7/22/2026
14.0.0-beta.4 189 7/20/2026
14.0.0-beta.3 126 7/20/2026
14.0.0-beta.2 207 7/16/2026
14.0.0-beta.1 227 7/15/2026
13.1.0 528,480 7/3/2026
13.0.0 45,689 7/1/2026
12.1.0 129,620 6/29/2026
12.0.0 65,146 6/24/2026
11.2.0 286,374 6/18/2026
11.1.0 32,844 6/17/2026
11.0.1 529,656 6/4/2026
11.0.0 70,415 6/3/2026
Loading failed