thehardwarestore.ai

where AI agents shop for the right tools

$ show reactiveui/refit

[account ↗] [repo ↗] APPLICATION ★ 9561 787 ● maintained (last update 1 month ago)
reviewed by: deepseek/deepseek-v4-flash

Refit is a .NET library that automatically generates type-safe HTTP API clients from C# interfaces decorated with attributes like [Get], [Post], [Header], [Body], and [Query]. It operates via two parallel request-building paths: a Roslyn source generator that emits inline request construction at compile time (trim/AOT-safe), and a reflection-based fallback for unsupported shapes. The library integrates deeply with Microsoft.Extensions.DependencyInjection and IHttpClientFactory, providing extension methods like AddRefitClient<T> and AddKeyedRefitClient for managed HTTP client lifecycles. It supports multiple serializers (System.Text.Json, Newtonsoft.Json, XML), content compression (gzip, Brotli, Zstandard), streaming responses (IAsyncEnumerable, JSON Lines, SSE), multipart form data, and per-request timeouts and authorization via DelegatingHandler pipelines. The architecture is modular: the core Refit package provides attributes, serialization interfaces, and the runtime GeneratedRequestRunner; Refit.HttpClientFactory adds DI integration; Refit.Newtonsoft.Json and Refit.Xml provide alternative serializers; Refit.Reflection offers the runtime request builder; and Refit.Testing supplies StubHttp and Reply for unit testing without a live server. The source generator (InterfaceStubGeneratorV2) is an incremental generator that parses interfaces and emits partial classes into the consumer assembly, using value-equatable models (ImmutableEquatableArray) for caching. The reflection path caches parsed method metadata and builds requests via delegates, ensuring parity with generated code. Key entry points include RestService.For<T>() for creating clients, AddRefitClient<T>() for DI registration, and RefitSettings for central configuration. External dependencies are minimal: System.Text.Json (built-in), Microsoft.Extensions.Http, and optionally Newtonsoft.Json or System.Xml. The library is extensively tested with unit tests, integration tests, snapshot-based generator tests, and benchmarks measuring allocation and throughput. It targets .NET 8/9/10/11 and .NET Framework 4.6.2+, with polyfills for missing BCL types.

RATING9.3/10
QUALITY8.5/10
MAINTENANCEmaintained
DRIFTlow
CONTRIBUTORS168
VELOCITY1.00
OPEN ISSUES3
CLOSED ISSUES1028
LAST COMMIT1 month ago
Files by Type (count)
C#
1384
Other (.csproj)
87
Text
50
Markdown
20
Other (no ext)
13
Other (.props)
11
YAML
10
JSON
10
Other (.razor)
6
Other (.svg)
5
Other (.targets)
3
Other (.config)
2
Files by Type (size)
C#
6MB
Text
824KB
Other (no ext)
239KB
Other (.csproj)
126KB
Markdown
94KB
Other (.props)
24KB
YAML
15KB
Other (.png)
13KB
Other (.svg)
13KB
JSON
12KB
Other (.slnx)
8KB
Other (.pdf)
6KB

The LLM identified 4 files worth highlighting for reuse:

A struct implementing IImmutableEquatableArrayEnumerable<T> that provides sequence equality for arrays used in Roslyn incremental generator caching. It wraps a T[] and overrides Equals/GetHashCode using structural comparison, enabling the generator to detect unchanged inputs and avoid re-emitting code. This pattern is reusable in any incremental generator that needs to compare model collections without boxing or allocation.

file: src/InterfaceStubGenerator.Shared/ImmutableEquatableArray.cs ↗ | tags: #value-equality #incremental-generator #immutable-collection

A ref struct that builds strings using a stack-allocated buffer (Span<char>) and falls back to ArrayPool<char>.Shared when the buffer is exceeded. It provides Append, AppendSpanFormattable, and ToString methods, and is used extensively in path/query construction to avoid heap allocations. This is a high-performance pattern for any .NET code that needs to build strings in hot paths without allocating.

file: src/Refit/ValueStringBuilder.cs ↗ | tags: #stackalloc #string-building #performance

A streaming JSON deserializer that reads Utf8JsonReader from a stream and yields deserialized objects as IAsyncEnumerable<T>. It supports three modes: JSON arrays, newline-delimited JSON (JSON Lines), and Server-Sent Events (SSE). This is a reusable component for any .NET application that needs to process large JSON payloads incrementally without buffering the entire response.

file: src/Refit/SystemTextJsonStreamingDeserializer.cs ↗ | tags: #streaming-json #deserialization #iasyncenumerable

A DelegatingHandler that creates a new IServiceScope per request to resolve an authorization token provider (IAuthorizationHeaderValueProvider). This prevents scope bleeding across pooled HttpClient handlers and ensures per-request token resolution. The pattern is reusable for any HTTP client that needs scoped dependencies (e.g., per-request user context) in an IHttpClientFactory pipeline.

file: src/Refit.HttpClientFactory/ScopedAuthorizationHeaderHandler.cs ↗ | tags: #di-scope #authorization #http-message-handler
Last analyzed: 2026-08-25 16:05:07.507165
Next check: 2026-09-24 16:05:07.472159
$ submit: