Refit 16.0.0

Prefix Reserved

Requires NuGet 2.12 or higher.

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

Showing the top 5 NuGet packages that depend on Refit:

Package Downloads
Refit.HttpClientFactory

Microsoft.Extensions.Http integration for Refit, adding AddRefitClient support for typed HttpClientFactory clients, dependency injection, handlers, and Polly-style HTTP pipelines.

Refit.Newtonsoft.Json

Newtonsoft.Json content serializer for Refit clients that need Json.NET converters, settings, or compatibility behavior instead of the default System.Text.Json serializer.

N3O.Umbraco.Extensions

TODO

Refit.Xml

XML content serializer for Refit clients that send or receive XML payloads through System.Xml.Serialization.XmlSerializer.

Serilog.Exceptions.Refit

Log exception details and custom properties that are not output in Exception.ToString(). Contains custom destructurers for Refit exceptions.

GitHub repositories (59)

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

Repository Stars
unoplatform/uno
Open-source platform for building cross-platform native Mobile, Web, Desktop, and Embedded apps from a single C#/XAML codebase. Work from any IDE/CLI with Hot Reload, Visual Designer, MCPs, and Skills built for modern .NET workflows. 200M+ NuGet downloads.
LykosAI/StabilityMatrix
Multi-Platform Package Manager for Stable Diffusion
elsa-workflows/elsa-core
The Workflow Engine for .NET
microsoft/ailab
Experience, Learn and Code the latest breakthrough innovations with Microsoft AI
Facepunch/sbox-public
s&box is a modern game engine, built on Valve's Source 2 and the latest .NET technology, it provides a modern intuitive editor for creating games
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!
Accelerider/Accelerider.Windows
A shell that runs Accelerider applications on the Windows platform.
SteveDunn/Vogen
A semi-opinionated library which is a source generator and a code analyser. It Source generates Value Objects
GoldenPotato137/PotatoVN
一款Visual Novel管理软件
b-editor/beutl
Cross-platform video editing (compositing) software.
desenvolvedor-io/dev-store
A microservices e-commerce reference application built with ASP.NET 9
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
newbe36524/Newbe.Mahua.Framework
本SDK为实现QQ机器人平台的大一统,支持多种机器人平台:酷Q、MyPCQQ、QQLight等
DevArchitecture/DevArchitecture
DevArchitecture Backend Project
dorisoy/Dorisoy.Pan
Dorisoy.Pan 是基于 .NET 10 的跨平台文档管理系统,使用 MS SQL 2012 / MySQL 8.0(或更高版本)后端数据库,您可以在 Windows、Linux 或 Mac 上运行它。项目中的所有方法都是异步的,支持 JWT 令牌身份验证,项目体系结构遵循 CQRS + MediatR 模式和最佳安全实践。源代码完全可定制,热插拔且清晰的体系结构,使开发定制功能和遵循任何业务需求变得容易。
RehanSaeed/Serilog.Exceptions
Log exception details and custom properties that are not output in Exception.ToString().
christianhelle/refitter
Generate Refit interfaces and contracts from OpenAPI (Swagger) specifications
Version Downloads Last Updated
16.0.0 0 9/20/2026
15.2.0 444,593 8/18/2026
15.1.0 77,272 8/15/2026
15.0.0 192,836 8/5/2026
15.0.0-beta.1 241 8/3/2026
14.0.1 313,893 7/26/2026
14.0.0 16,594 7/25/2026
14.0.0-beta.5 272 7/22/2026
14.0.0-beta.4 295 7/20/2026
14.0.0-beta.3 201 7/20/2026
14.0.0-beta.2 316 7/16/2026
14.0.0-beta.1 310 7/15/2026
13.1.0 645,319 7/3/2026
13.0.0 64,950 7/1/2026
12.1.0 150,254 6/29/2026
12.0.0 85,765 6/24/2026
11.2.0 363,418 6/18/2026
11.1.0 41,093 6/17/2026
11.0.1 658,180 6/4/2026
11.0.0 105,003 6/3/2026
Loading failed