ZeroAlloc.Rest.SystemTextJson 3.3.4

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

ZeroAlloc.Rest

NuGet Build License: MIT AOT GitHub Sponsors

Describe your HTTP API as a C# interface and get a typed REST client generated at compile time: a Refit alternative with no reflection, NativeAOT-ready, and no allocation beyond what the same call written by hand costs.

Why ZeroAlloc.Rest

  • Allocates exactly what hand-written HttpClient code does. A generated GET of a small DTO allocates 1,688 B per call, the same as the request written by hand, and a test fails the build if it ever allocates more.
  • 1.7–3.6× faster than Refit with 1.3–1.5× less allocation per call, measured in the same run.
  • Works under NativeAOT and trimming. No reflection, no IL emit, no DynamicMethod; CI publishes a NativeAOT app and fails on any trim or AOT warning.
  • Mistakes surface at compile time. A route template that does not match the method's parameters, or a Result error type with no mapper, is a compiler diagnostic.

Install

dotnet add package ZeroAlloc.Rest
dotnet add package ZeroAlloc.Rest.DependencyInjection
dotnet add package ZeroAlloc.Rest.SystemTextJson

The source generator ships inside ZeroAlloc.Rest. The other two give you the IHttpClientFactory registration and the JSON serializer used below.

Quick start

using System.Text.Json;
using System.Text.Json.Serialization;
using Microsoft.Extensions.DependencyInjection;
using ZeroAlloc.Rest.Attributes;
using ZeroAlloc.Rest.SystemTextJson;

var services = new ServiceCollection();
services.AddIUserApi(options => // generated from the interface name
{
    options.BaseAddress = new Uri("https://jsonplaceholder.typicode.com");
    options.UseSerializer(new SystemTextJsonSerializer(AppJsonContext.Default));
});

var api = services.BuildServiceProvider().GetRequiredService<IUserApi>();
var user = await api.GetUserAsync(1);
Console.WriteLine($"{user.Id}: {user.Name}"); // 1: Leanne Graham

[ZeroAllocRestClient]
public interface IUserApi
{
    [Get("/users/{id}")]
    Task<UserDto> GetUserAsync(int id, CancellationToken ct = default);
}

public sealed record UserDto(int Id, string Name);

[JsonSourceGenerationOptions(JsonSerializerDefaults.Web)]
[JsonSerializable(typeof(UserDto))]
internal sealed partial class AppJsonContext : JsonSerializerContext;

The generator writes UserApiClient, a sealed class implementing IUserApi, at compile time. Inject IUserApi wherever you need it.

What you get

  • Every parameter kind: path segments including {**path} catch-alls, [Query], [Body] and [Header].
  • Errors as values: return Result<T, HttpError> from ZeroAlloc.Results and 4xx/5xx responses, network failures and timeouts come back as a failure instead of an exception, or map them to your own error type.
  • Pluggable serializers: System.Text.Json, MemoryPack, MessagePack, or your own, and a different one per method when an API mixes formats.
  • Streaming responses for large bodies, without the copy HttpClient makes by default.
  • IHttpClientFactory integration through a generated Add{Interface} extension, or construct the client by hand without DI.
  • Tracing and metrics on the BCL ActivitySource and Meter, ready for OpenTelemetry: Telemetry.
  • OpenAPI import: generate the interface, models and JSON context from a spec with the zeroalloc generate CLI or an MSBuild item: OpenAPI code generation.
  • Retry, timeout, circuit breaker and rate limiting with ZeroAlloc.Rest.Resilience and ZeroAlloc.Resilience: Resilience.

Performance

Against Refit, in-memory handler, no network I/O. .NET 10.0.7, i9-12900HK, BenchmarkDotNet v0.15.8. Allocations as BenchmarkDotNet reports them; speed is a same-run ratio.

Call ZA vs Refit Refit alloc ZA alloc
GET 3.6× faster 2.88 KB 1.88 KB
GET with query parameter 3.6× faster 3.55 KB 1.99 KB
POST 1.7× faster 3.46 KB 2.64 KB

Refit scans attributes with reflection and invokes expression trees on every call; the generated client is plain code. Raw HttpClient rows, DELETE, Result<T>, serializer throughput and the per-call allocation breakdown: docs/benchmarks.md.

Learn more

Product Compatible and additional computed target framework versions.
.NET 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (13)

Showing the top 5 NuGet packages that depend on ZeroAlloc.Rest.SystemTextJson:

Package Downloads
TypeSafe-AI.Sdk

TypeSafe-AI .NET SDK

Rag.NET.WebSearch.Tavily

Tavily web search provider for Rag.NET's corrective RAG (CRAG) fallback

Rag.NET.VectorStores.Weaviate

Weaviate vector store for Rag.NET

Rag.NET.DataProviders.Bitbucket

Bitbucket data provider for Rag.NET

Rag.NET.DataProviders.Linear

Linear issue tracker data provider for Rag.NET

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
3.3.4 0 10/16/2026
3.3.3 53 10/15/2026
3.3.2 1,146 10/11/2026
3.3.1 980 10/10/2026
3.3.0 126 10/10/2026
3.2.1 1,428 10/4/2026
3.2.0 453 9/30/2026
3.1.0 847 9/28/2026
3.0.0 409 9/28/2026
2.2.0 234 9/27/2026
2.1.0 563 9/26/2026
2.0.1 240 9/25/2026
2.0.0 111 9/25/2026
1.3.5 260 9/24/2026
1.3.4 1,869 9/20/2026
1.3.3 165 9/20/2026
1.3.2 98 9/19/2026
1.3.1 2,325 8/7/2026
1.3.0 114 8/7/2026
1.1.3 287 5/13/2026
Loading failed