NexArc.InterfaceBridge.CodeGenerator 1.0.2

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

NexArc.InterfaceBridge

A type-safe, interface-based REST API framework for .NET that creates tightly coupled connections between client and server with full AOT (Ahead-of-Time) compilation support.

Features

  • Type-Safe API Contracts: Define your REST APIs using C# interfaces with attributes
  • AOT-Compatible: Full support for iOS and other platforms requiring AOT compilation
  • Source Generation: Automatic client code generation using Roslyn source generators
  • System.Text.Json Integration: Built-in support for JsonSerializable partial classes
  • Minimal Boilerplate: Write interfaces once, generate both client and server implementations
  • Multiple Content Types: Supports form data, multipart/form-data, and file uploads
  • Async/Await: Built-in support for Task<T> and CancellationToken

Installation

Install the NuGet packages:

# For server-side implementation
dotnet add package NexArc.InterfaceBridge
dotnet add package NexArc.InterfaceBridge.Server

# For client-side code generation
dotnet add package NexArc.InterfaceBridge
dotnet add package NexArc.InterfaceBridge.CodeGenerator

Quick Start

1. Define Your API Interface (Shared)

using NexArc.InterfaceBridge;

[RestConnector("api/hello")]
public interface IHelloApi
{
    [Rest(HttpMethod.Get, "greet/{name}")]
    Task<string> Greet(string name, CancellationToken cancellationToken = default);
}

2. Implement the Server

using NexArc.InterfaceBridge.Server;

var builder = WebApplication.CreateBuilder(args);

// Register the InterfaceBridge
builder.UseInterfaceBridge<IHelloApi, HelloApi>();

var app = builder.Build();

// Map routes based on interface methods
app.UseInterfaceBridges();

app.Run("http://localhost:5199");

public class HelloApi : IHelloApi
{
    public Task<string> Greet(string name, CancellationToken cancellationToken = default)
    {
        return Task.FromResult($"Hello, {name}!");
    }
}

3. Generate and Use the Client

using Examples.Client;
using NexArc.InterfaceBridge;

// Create a partial class with the Bridge attribute
[Bridge(typeof(IHelloApi))]
public partial class HelloClient : IHelloApi
{
    public HttpClient HttpClient { get; }

    public HelloClient(HttpClient httpClient)
    {
        HttpClient = httpClient;
    }
}

// Use the generated client
var http = new HttpClient
{
    BaseAddress = new Uri("http://localhost:5199/")
};

var client = new HelloClient(http);
var result = await client.Greet("World");
Console.WriteLine(result); // Output: Hello, World!

AOT Support with System.Text.Json

For iOS and other AOT platforms, use JsonSerializable partial classes:

using System.Text.Json.Serialization;

[JsonSourceGenerationOptions(WriteIndented = true)] 
[JsonSerializable(typeof(YourResponseType))]
[JsonSerializable(typeof(YourRequestType))]
public partial class AppJsonContext : JsonSerializerContext { }

[Bridge(typeof(IYourApi), JsonSerializerContext = typeof(AppJsonContext))]
public partial class YourClient : IYourApi
{
    public HttpClient HttpClient { get; }

    public YourClient(HttpClient httpClient)
    {
        HttpClient = httpClient;
    }
}

Attributes

[RestConnector]

Applied to interfaces to define the base route prefix for all methods.

[Rest]

Applied to interface methods to define HTTP method and route template. Supports:

  • GET: Parameters from route template, remaining in query string
  • POST/PUT/PATCH: Parameters from route template, remaining in body (form-encoded or multipart)
  • DELETE: Parameters from route template

[Bridge]

Applied to partial client classes to generate the implementation. Parameters:

  • bridgeInterface: The interface to implement
  • JsonSerializerContext (optional): For AOT support
  • DefaultBodyType (optional): Override default body encoding

Content Types

The framework automatically selects the appropriate content type:

  • FormUrlEncoded: Default for POST/PUT/PATCH
  • MultipartFormData: Automatically used when FilePart parameters are present
  • JSON: Use with JsonSerializerContext for AOT support

Advanced Features

File Uploads

Use FilePart for file uploads (automatically switches to multipart/form-data):

[Rest(HttpMethod.Post, "upload")]
Task<UploadResponse> UploadFile(string description, FilePart file, CancellationToken cancellationToken = default);

Custom Body Types

Override the default body type:

[Rest(HttpMethod.Post, "data", BodyType = BodyType.MultipartFormData)]
Task PostData(string name, int value, CancellationToken cancellationToken = default);

License

MIT

Repository

https://github.com/nexarcdev/InterfaceBridge

There are no supported framework assets in this package.

Learn more about Target Frameworks and .NET Standard.

  • .NETStandard 2.0

    • No dependencies.

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.0.10 143 1/30/2026
1.0.9 118 1/16/2026
1.0.8 173 12/21/2025
1.0.7 432 12/11/2025
1.0.6 425 12/11/2025
1.0.5 128 12/6/2025
1.0.4 211 12/3/2025
1.0.3 128 11/29/2025
1.0.2 183 11/27/2025
1.0.1 192 11/24/2025