AnyProtocol.Protocol.Rest 1.0.2

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

<p align="center"> <picture> <source media="(prefers-color-scheme: dark)" srcset="docs/assets/AnyProtocol_logo_dark.svg"> <source media="(prefers-color-scheme: light)" srcset="docs/assets/AnyProtocol_logo_light.svg"> <img alt="AnyProtocol" src="docs/assets/AnyProtocol_logo_dark.svg" width="420"> </picture> </p>

AnyProtocol

AnyProtocol is a .NET contract-first messaging library. A single interface can be registered as a local service or carried over REST, gRPC, Kafka, RabbitMQ, or ZeroMQ, with request/reply, events, generated proxies, transport validation, health checks, and built-in diagnostics.

One logical server registration can be exposed through several protocols at the same time. Each client selects one protocol in its own configuration; neither the contract nor the service implementation contains transport-specific code.

AnyProtocol overview: one contract, any transport

Stability: The repository targets .NET 10 and the public API is still evolving. Pin package versions, validate transport semantics for your workload, and use the source generator plus serializer metadata before Native AOT deployment. Transport support is intentionally capability-based; a feature listed for one transport is not implied for the others.

Transport matrix

Transport Request/reply Events/pub-sub Streaming Delivery Durability Ordering
InMemory Emulated Yes Emulated At most once Volatile Per channel
REST Native No No At most once Volatile None
gRPC Native No Native server streaming At most once Volatile None
Kafka Emulated Yes Emulated At least once Durable Per partition
RabbitMQ Emulated Yes Emulated At least once Durable Per channel¹
ZeroMQ Emulated Yes Emulated At most once Volatile Per channel

¹ Per-channel ordering requires one active consumer/handler for the queue; concurrent handlers can complete out of order.

See transport semantics before choosing a production transport.

Prerequisites

  • .NET SDK 10.0.300 or a compatible newer feature band
  • A Kafka broker for Kafka transport
  • A RabbitMQ broker for RabbitMQ transport
  • Reachable TCP endpoints for ZeroMQ
  • ASP.NET Core hosting for REST or gRPC servers

From source:

git clone https://github.com/MCKanpolat/AnyProtocol.git
cd AnyProtocol
dotnet restore AnyProtocol.slnx

For an application using Microsoft DI and the local transport:

dotnet add package AnyProtocol.DependencyInjection.Microsoft
dotnet add package AnyProtocol.Protocol.InMemory
dotnet add package AnyProtocol.Serializer.TextJson

Package map

Purpose Package
Contracts and core pipeline AnyProtocol, AnyProtocol.Abstraction
Microsoft DI and hosted lifecycle AnyProtocol.DependencyInjection.Microsoft
Payload serialization (JSON / MessagePack) AnyProtocol.Serializer.TextJson, AnyProtocol.Serializer.MessagePack
Envelope codecs (MessagePack / Protobuf / compression) AnyProtocol.Encoder.MessagePack, AnyProtocol.Encoder.Protobuf, AnyProtocol.Encoder.Compression
In-process transport AnyProtocol.Protocol.InMemory
REST client / ASP.NET Core server AnyProtocol.Protocol.Rest, AnyProtocol.Protocol.Rest.AspNetCore
gRPC client / ASP.NET Core server AnyProtocol.Protocol.Grpc, AnyProtocol.Protocol.Grpc.AspNetCore
Kafka / RabbitMQ / ZeroMQ AnyProtocol.Protocol.Kafka, AnyProtocol.Protocol.RabbitMq, AnyProtocol.Protocol.ZeroMq
Optional MCP exposure AnyProtocol.Mcp, AnyProtocol.Mcp.AspNetCore
Compile-time contract generation AnyProtocol.Generator

Envelope codecs

Payload serialization and transport envelope encoding are independent choices:

application message -> IMessageSerializer -> TransportEnvelope -> IEnvelopeCodec -> transport frame

gRPC and ZeroMQ use the backwards-compatible BinaryEnvelopeCodec by default. Both transports also accept an IEnvelopeCodec, so MessagePack or Protobuf framing can be selected and compression can decorate any base codec. Sender and receiver must use compatible codec configurations.

IEnvelopeCodec codec = new CompressedEnvelopeCodec(
    new ProtobufEnvelopeCodec(),
    new CompressedEnvelopeCodecOptions
    {
        Algorithm = CompressionAlgorithm.Brotli
    });

var grpc = new GrpcMessagingProtocol(
    channel,
    codec,
    disposeChannel: true);

var zeroMq = new ZeroMqMessagingProtocol(options, codec);

// ASP.NET Core gRPC server:
builder.Services.AddSingleton<IEnvelopeCodec>(codec);
builder.Services.AddAnyProtocolGrpc();

See the envelope codec guide for package selection, wire contracts, limits, and transport configuration.

Minimal request/reply

using AnyProtocol.Abstraction;
using AnyProtocol.DependencyInjection.Microsoft;
using AnyProtocol.Protocol.InMemory;
using AnyProtocol.Serializer.TextJson;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;

var builder = Host.CreateApplicationBuilder(args);
builder.Services.AddAnyProtocol(link => link
    .UseSerializer(new TextJsonMessageSerializer())
    .AddTransport("default", new InMemoryMessagingProtocol())
    .AddClient<IOrders>()
    .AddServer<IOrders, Orders>());

using var host = builder.Build();
await host.StartAsync();

var client = host.Services.GetRequiredService<IOrders>();
var result = await client.GetAsync(new GetOrder("42"), CancellationToken.None);
Console.WriteLine(result.Status);

await host.StopAsync();

[Channel("orders")]
public interface IOrders
{
    [Idempotent]
    ValueTask<Order> GetAsync(GetOrder request, CancellationToken cancellationToken);
}

public sealed record GetOrder(string Id);
public sealed record Order(string Id, string Status);

public sealed class Orders : IOrders
{
    public ValueTask<Order> GetAsync(GetOrder request, CancellationToken cancellationToken)
        => ValueTask.FromResult(new Order(request.Id, "ready"));
}

One service, multiple protocols

Use the built-in ProtocolKey values for compile-time-friendly configuration. Custom keys remain available for third-party protocols or named instances used by different registrations.

link.AddRestServer(ProtocolKey.Rest)
    .AddGrpcServer(ProtocolKey.Grpc)
    .AddServer<IOrders, Orders>(server => server.UseProtocols(
        ProtocolKey.Rest,
        ProtocolKey.Grpc,
        ProtocolKey.Mcp));

The host maps each selected endpoint once:

services.AddAnyProtocolRest();
services.AddAnyProtocolGrpc();
services.AddAnyProtocolMcp();

app.MapAnyProtocol();
app.MapAnyProtocolGrpc();
app.MapAnyProtocolMcp();

A gRPC client and a REST client keep the same IOrders contract but choose independently:

link.AddClient<IOrders>(client => client.UseProtocol(ProtocolKey.Grpc));
// In another application:
link.AddClient<IOrders>(client => client.UseProtocol(ProtocolKey.Rest));

The choice can come from deployment configuration without changing the contract registration:

services.AddAnyProtocol(
    configuration.GetSection("AnyProtocol"),
    link => link.AddClient<IOrders>("OrdersClient"));
{
  "AnyProtocol": {
    "Clients": {
      "OrdersClient": { "Protocol": "Grpc" }
    }
  }
}

Every selected protocol is validated against every contract operation during startup. An incompatible selection fails configuration instead of exposing a partial service. Duplicate native REST/gRPC bindings for one contract are rejected. MCP publishes only methods marked with [McpTool]; selecting MCP without registering and hosting its adapter stops application startup.

[Idempotent] permits configured retries; it does not provide deduplication.

Documentation and samples

Run the samples with:

dotnet run --project samples/OrderSystem.McpHost
dotnet run --project samples/OrderSystem.McpHost -- --stdio
dotnet run --project samples/AnyProtocol.AotSample
dotnet run --project samples/OrderSystem.MultiProtocol/OrderSystem.Server
dotnet run --project samples/OrderSystem.MultiProtocol/OrderSystem.Client -- --protocol Rest
dotnet run --project samples/OrderSystem.MultiProtocol/OrderSystem.Client -- --protocol Grpc

The multi-protocol order server uses http://localhost:5080 for REST/MCP and http://localhost:5081 for gRPC.

License

AnyProtocol is licensed under LGPL-3.0-or-later. Applications may link to the AnyProtocol libraries under their own license terms. Distributed changes to the AnyProtocol libraries themselves must remain available under LGPL-3.0-or-later with their corresponding source code.

The AnyProtocol name and logo are governed separately by the trademark policy. Forks must not present themselves as the official AnyProtocol project.

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 (1)

Showing the top 1 NuGet packages that depend on AnyProtocol.Protocol.Rest:

Package Downloads
AnyProtocol.Protocol.Rest.AspNetCore

AnyProtocol is a .NET messaging and communication library for building protocol-flexible distributed applications.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.9 115 8/29/2026
1.0.6 118 8/16/2026
1.0.4 109 8/9/2026
1.0.3 111 8/9/2026
1.0.2 104 8/9/2026
1.0.1 98 8/8/2026
1.0.0 97 8/8/2026

See the GitHub release notes for the changes included in this version.