reactiveui /refit

The automatic type-safe REST library for .NET. Refit turns a REST API into a C# interface and generates the HttpClient implementation, with support for HttpClientFactory, pluggable serializers and a testing package.

★ 9,585⑂ 780👁 160⑃ 1,231● 1,033▤ 92
C#NOASSERTIONCreated 2013-07-22www.reactiveui.net/documentation/refit/
More from this author
Download: 16.4.016.4.0 ↓16.4.02026-10-17
+1
Daily
9,585
stars
780
forks
160
watchers
1,231
prs
1,033
issues
92
releases

README

!Refit

 Refit




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. Release streamed replies chunk by chunk, choose how request bodies are captured, and control simulated time. |
| 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, ValueTask, IObservable and response wrappers | Return types and responses |
| Streamed JSON arrays, JSON Lines and server-sent events | Streaming |
| Lazy paging over cursors, offsets and Link headers with PagedEnumerable | Pagination |
| JSON contexts registered at client creation and per-method JsonTypeInfo parameters | JSON |
| HTTP, transport and deserialization failures | Errors |
| HTTP-aware retries with provider header hints and deterministic tests | HTTP retries and local guide |
| Retries, timeouts and a fresh token for each retry with Microsoft's resilience handler | Resilience |
| OpenTelemetry spans and request-duration metrics labelled by Refit method and route template | Telemetry |
| Local replies, request verification and simulated faults | Testing |
| Deterministic tests of streamed replies, stalled or dropped bodies, streaming uploads and simulated time | Testing streams, uploads and time |

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, pa

Top issues

Discussions

Latest release

16.4.0 v16.4.0 2026-10-17
Summary

Refit 16.4.0 adds opt-in HTTP-aware retries, new query naming and relative URL options, and fixes for parameter binding and response handling. Existing clients keep their current behavior unless you enable the new options.

 HTTP-aware retries

HttpRetryHandler works with Refit clients and ordinary HttpClient calls. It needs no extra resilience package or changes to your API interface.

- By default, it allows three retries after the first send for GET, HEAD, OPTIONS and TRACE. It retries HTTP 408, 429, 500, 502, 503 and 504, plus HttpRequestException. A 403 retries only when the conf

Snapshot: 2026-11-16T09:23:14Z · Data license Apache-2.0 · JSON