Refit 16.0.0

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.

Showing the top 20 packages that depend on Refit.

Packages Downloads
Nuke.Common
Cross-platform build automation system
166
Nuke.Common
Cross-platform build automation system
167
Nuke.Common
Cross-platform build automation system
168
Nuke.Common
Cross-platform build automation system
169
Nuke.Common
Cross-platform build automation system
170
Nuke.Common
Cross-platform build automation system
172
Nuke.Common
Cross-platform build automation system
173
Nuke.Common
Cross-platform build automation system
174
Nuke.Common
Cross-platform build automation system
175
Nuke.Common
Cross-platform build automation system
177
Nuke.Common
Cross-platform build automation system
178
Nuke.Common
Cross-platform build automation system
180
Nuke.Common
Cross-platform build automation system
184

https://github.com/reactiveui/refit/releases

.NET 10.0

.NET Framework 4.7.2

.NET Framework 4.8

.NET Framework 4.8.1

.NET 8.0

.NET 9.0

.NET Framework 4.7.1

.NET 11.0

.NET Framework 4.6.2

.NET Framework 4.7

Version Downloads Last updated
16.1.0 0 09/21/2026
16.0.0 3 09/20/2026
15.2.0 20 08/18/2026
15.1.0 16 08/16/2026
15.0.0 17 08/06/2026
15.0.0-beta.1 19 08/03/2026
14.0.1 22 07/28/2026
14.0.0 23 07/26/2026
14.0.0-beta.5 26 07/23/2026
14.0.0-beta.4 22 07/22/2026
14.0.0-beta.3 25 07/20/2026
14.0.0-beta.2 20 07/19/2026
14.0.0-beta.1 24 07/15/2026
13.1.0 28 07/03/2026
13.0.0 28 07/01/2026
12.1.0 29 06/30/2026
12.0.0 25 06/24/2026
11.2.0 21 06/18/2026
11.1.0 30 06/17/2026
11.0.1 29 06/04/2026
11.0.0 27 06/04/2026
10.2.0 25 06/04/2026
10.1.6 49 03/21/2026
10.0.1 64 02/09/2026
9.0.2 83 12/01/2025
8.0.0 151 11/13/2024
7.2.22 134 11/14/2024
7.2.1 155 09/19/2024
7.2.0 133 09/20/2024
7.1.2 169 07/22/2024
7.0.0 154 07/22/2024
6.3.2 160 07/22/2024
6.2.16 155 07/22/2024
6.1.15 155 07/22/2024
6.0.94 166 07/22/2024
6.0.38 167 07/22/2024
6.0.24 194 07/22/2024
6.0.21 163 07/22/2024
6.0.15 154 07/22/2024
6.0.8 158 07/22/2024
6.0.1 142 07/22/2024
6.0.0-preview.128 144 07/22/2024
6.0.0-preview.96 138 07/22/2024
6.0.0-preview.37 151 07/22/2024
5.2.4 152 07/22/2024
5.2.1 175 07/22/2024
5.1.67 142 07/22/2024
5.1.54 141 07/22/2024
5.1.27 153 07/22/2024
5.0.23 149 07/22/2024
5.0.15 157 07/22/2024
4.8.14 168 07/22/2024
4.7.51 161 07/22/2024
4.7.9 162 07/22/2024
4.6.107 153 07/22/2024
4.6.99 158 07/22/2024
4.6.90 173 07/22/2024
4.6.58 134 07/22/2024
4.6.48 199 07/22/2024
4.6.30 156 07/22/2024
4.6.16 152 07/22/2024
4.5.6 163 07/22/2024
4.4.17 150 07/22/2024
4.3.0 139 07/22/2024
4.2.0 149 07/22/2024
4.1.0 142 07/22/2024
4.0.1 140 07/22/2024
4.0.0 149 07/22/2024
3.1.0 147 07/22/2024
3.0.1 149 07/22/2024
3.0.0 148 07/22/2024
2.4.1 146 07/22/2024
2.4.0 157 07/22/2024
2.3.0 164 07/22/2024
2.2.1 148 07/22/2024
2.2.0 185 07/22/2024
2.1.0 159 07/22/2024
2.0.2 166 07/22/2024
2.0.1 165 07/22/2024
2.0.0 161 07/22/2024
1.3.0 174 07/22/2024
1.2.0 164 07/22/2024
1.1.0 149 07/22/2024
1.0.0 162 07/22/2024