ZeroAlloc.Rest.MessagePack 0.1.1

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

ZeroAlloc.Rest

NuGet Build License: MIT

ZeroAlloc.Rest is a source-generated, Native AOT-compatible REST client for .NET 10+. Define your HTTP API as a C# interface — the Roslyn generator emits a fully type-safe, zero-reflection implementation at compile time. No runtime code generation, no IL emit, no allocations beyond the HTTP layer itself.

Install

dotnet add package ZeroAlloc.Rest
dotnet add package ZeroAlloc.Rest.Generator
dotnet add package ZeroAlloc.Rest.SystemTextJson

Or via <PackageReference>:

<PackageReference Include="ZeroAlloc.Rest" Version="x.y.z" />
<PackageReference Include="ZeroAlloc.Rest.Generator"
                  Version="x.y.z"
                  OutputItemType="Analyzer"
                  ReferenceOutputAssembly="false" />
<PackageReference Include="ZeroAlloc.Rest.SystemTextJson" Version="x.y.z" />

Quick Start

1. Define your API interface:

using ZeroAlloc.Rest.Attributes;

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

    [Get("/users")]
    Task<List<UserDto>> ListUsersAsync([Query] string? name = null, CancellationToken ct = default);

    [Post("/users")]
    Task<UserDto> CreateUserAsync([Body] CreateUserRequest request, CancellationToken ct = default);

    [Delete("/users/{id}")]
    Task DeleteUserAsync(int id, CancellationToken ct = default);
}

2. Register in DI:

builder.Services.AddIUserApi(options =>
{
    options.BaseAddress = new Uri("https://api.example.com");
    options.UseSerializer<SystemTextJsonSerializer>();
});

3. Inject and use:

public class UserService(IUserApi api)
{
    public Task<UserDto> GetAsync(int id) => api.GetUserAsync(id);
}

The generator produces UserApiClient — a sealed class implementing IUserApi — at compile time. No reflection, no proxies, no DynamicMethod.

Performance

Measured on .NET 10.0.4, Windows 11, X64. In-memory handler; no real network I/O. See docs/benchmarks.md for methodology and full results.

Method Mean vs Refit Allocated
Raw HttpClient (GET baseline) 1,648 ns 1.38 KB
ZeroAlloc.Rest GET 1,933 ns 3.2× faster 1.74 KB
Refit GET 6,123 ns 3.03 KB
ZeroAlloc.Rest QueryParam 2,474 ns 5.5× faster 1.85 KB
Refit QueryParam 13,509 ns 3.67 KB

Features

  • Source-generated — zero runtime reflection; compile-time type safety
  • Native AOT compatible — no DynamicMethod, no IL emit, no Type.GetType
  • Per-method serializer override[Serializer(typeof(MySerializer))] for mixed protocols
  • Path, query, body, and header parameters{id}, [Query], [Body], [Header("X-Api-Key")]
  • Result<T, HttpError> — typed success/error returns via ZeroAlloc.Results; no exception-throwing on 4xx/5xx
  • OpenAPI code generationOpenApiInterfaceGenerator API + MSBuild <ZeroAllocApiSpec> task
  • Pluggable serializers — System.Text.Json, MemoryPack, MessagePack, or bring your own
  • IHttpClientFactory integrationAddI{Interface} generated extension method

Documentation

Page Description
Getting Started Install, register, and make your first call
Routing Route templates and path parameters
Parameters Query, body, header, and path parameters
Serialization Built-in serializers and custom IRestSerializer
Dependency Injection Generated DI extension and IHttpClientFactory
Native AOT AOT safety guarantees and publish configuration
OpenAPI Code Generation Generate interfaces from OpenAPI specs
Benchmarks Performance comparison vs Refit and raw HttpClient
Testing Testing patterns with WireMock.Net
Advanced Result<T, HttpError>, multiple serializers, edge cases
Cookbook End-to-end recipes

License

MIT

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

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.1.3 85 5/13/2026
1.1.2 86 5/12/2026
1.1.1 89 5/2/2026
1.1.0 83 5/1/2026
1.0.2 88 4/29/2026
1.0.1 101 4/29/2026
1.0.0 101 4/28/2026
0.2.0 93 4/14/2026
0.1.5 93 4/25/2026
0.1.4 89 4/25/2026
0.1.3 93 4/14/2026
0.1.2 109 4/2/2026
0.1.1 102 4/1/2026
0.1.0 102 3/31/2026