FluentYarp 1.0.1

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

Fluent YARP API ๐Ÿš€

NuGet Version Build Status License: MIT Downloads

A strongly-typed, developer-friendly configuration library for Microsoft YARP (Yet Another Reverse Proxy) that eliminates JSON configuration pain points.

Say goodbye to repetitive JSON configuration and hello to IntelliSense-driven, compile-time validated proxy setup.

โœจ Why Fluent YARP API?

Before: Repetitive JSON Hell ๐Ÿ˜ต

{
  "route1": {
    "ClusterId": "catalog",
    "Match": { 
      "Path": "/catalog-api/api/catalog/items", 
      "QueryParameters": [{"Name": "api-version", "Values": ["1.0", "1"], "Mode": "Exact"}] 
    },
    "Transforms": [{ "PathRemovePrefix": "/catalog-api" }]
  },
  "route2": {
    "ClusterId": "catalog",
    "Match": { 
      "Path": "/catalog-api/api/catalog/items/{id}", 
      "QueryParameters": [{"Name": "api-version", "Values": ["1.0", "1"], "Mode": "Exact"}] 
    },
    "Transforms": [{ "PathRemovePrefix": "/catalog-api" }]
  }
  // ... 8 more nearly identical routes ๐Ÿ˜ฑ
}

After: Clean, Type-Safe Configuration โœจ

builder.Services.AddFluentYarpProxy(proxy =>
    proxy.AddRouteGroup("catalog", group =>
        group.WithBasePath("/catalog-api/api/catalog")
             .RequireApiVersion("1.0", "1")
             .AddTransform(t => t.RemovePathPrefix("/catalog-api"))
             .ToCluster("catalog")
             .Get("items")
             .Get("items/{id}")
             .Post("items"))
         .AddCluster("catalog", c => c.WithPrimaryDestination("http://catalog-api")));

๐ŸŽฏ Key Benefits

  • ๐Ÿ›ก๏ธ Type Safety: Compile-time validation instead of runtime JSON errors
  • ๐Ÿ”„ Zero Duplication: Shared configuration across route groups
  • ๐Ÿ’ก IntelliSense: Rich code completion and documentation
  • ๐Ÿงช Testability: Built-in testing utilities for route validation
  • ๐Ÿ“ˆ Maintainability: Clear, readable configuration code
  • โšก Performance: Zero runtime overhead compared to native YARP

๐Ÿš€ Quick Start

Installation

dotnet add package FluentYarp

Simple Example

using FluentYarp;
using FluentYarp.Extensions;

var builder = WebApplication.CreateBuilder(args);

// Replace complex JSON with simple fluent configuration
builder.Services.AddFluentYarpProxy(proxy =>
    proxy.AddRouteGroup("api", group =>
        group.WithBasePath("/api/v1")
             .RequireApiVersion("1.0")
             .Get("users/{id}", r => r.ToCluster("users"))
             .Post("users", r => r.ToCluster("users")))
         .AddCluster("users", c => c.WithPrimaryDestination("http://users-api")));

var app = builder.Build();
app.UseFluentYarpProxy();
app.Run();

Real-World API Gateway

builder.Services.AddFluentYarpProxy(proxy =>
{
    proxy.UseApiGatewayProfile()  // Common API gateway settings
         
         // Catalog microservice routes
         .AddRouteGroup("catalog", group =>
             group.WithBasePath("/api/catalog")
                  .RequireApiVersion("1.0")
                  .AddTransform(t => t.AddCorrelationId())
                  .ToCluster("catalog")
                  .Get("items")
                  .Get("items/{id}")
                  .Get("items/search")
                  .Post("items"))
         
         // Order microservice routes
         .AddRouteGroup("orders", group =>
             group.WithBasePath("/api/orders")
                  .RequireHeader("Authorization", "Bearer")
                  .ToCluster("orders")
                  .Get("{userId}/orders")
                  .Post(""))
         
         // Clusters with load balancing
         .AddCluster("catalog", c => c
             .WithPrimaryDestination("http://catalog-api")
             .WithBackupDestination("http://catalog-backup")
             .WithLoadBalancing(LoadBalancingPolicy.RoundRobin)
             .WithHealthCheck("/health"))
         
         .AddCluster("orders", c => c
             .WithPrimaryDestination("http://orders-api")
             .WithSessionAffinity(SessionAffinityPolicy.Cookie));
});

๐Ÿ”ง Advanced Features

Route Groups with Shared Configuration

.AddRouteGroup("admin-api", group =>
    group.WithBasePath("/admin")
         .RequireHeader("X-Admin-Key", "secret")
         .RequireApiVersion("2.0")
         .AddTransform(t => t.AddHeader("X-Internal", "true"))
         // All routes inherit the above configuration
         .Get("users")
         .Get("users/{id}")
         .Delete("users/{id}"))

Multiple Environments

.ForEnvironment("Development", dev =>
    dev.AddCluster("users", c => c.WithDestination("dev", "http://localhost:5001")))
.ForEnvironment("Production", prod =>
    prod.AddCluster("users", c => c
        .WithPrimaryDestination("http://users-api")
        .WithBackupDestination("http://users-backup")))

Built-in Testing

[Test]
public async Task Should_Route_Correctly()
{
    var proxy = FluentProxyBuilder.Create()
        .Get("/api/users/{id}", r => r.ToCluster("users"))
        .AddCluster("users", c => c.WithPrimaryDestination("http://users-api"));

    await proxy.TestRoute("/api/users/123")
        .ShouldRouteToCluster("users")
        .ShouldApplyTransform("PathRemovePrefix");
}

๐Ÿ“š Documentation

๐Ÿ› ๏ธ Use Cases

โœ… Perfect For

  • API Gateways - Route external requests to internal microservices
  • Service Mesh - Internal service-to-service communication
  • Load Balancing - Distribute traffic across multiple instances
  • Legacy Migration - Gradually modernize APIs
  • Multi-tenant SaaS - Route requests based on tenant context

๐Ÿ“ฆ Pre-built Extensions

// E-commerce platform routes
proxy.AddCatalogApiRoutes("/api/catalog")
     .AddOrderingApiRoutes("/api/orders")
     .AddPaymentApiRoutes("/api/payments")
     .AddIdentityRoutes("/auth");

// Standard CRUD operations
proxy.AddStandardCrudRoutes("/api/users", "users")
     .AddStandardCrudRoutes("/api/products", "products");

๐Ÿ”„ Migration from JSON

Converting your existing YARP JSON configuration is straightforward:

Step 1: Install FluentYarp

dotnet add package FluentYarp

Step 2: Replace your service registration

// Remove this
builder.Services.AddReverseProxy()
    .LoadFromConfig(builder.Configuration.GetSection("ReverseProxy"));

// Add this
builder.Services.AddFluentYarpProxy(proxy => {
    // Your fluent configuration here
});

Step 3: Convert routes to fluent syntax (see Migration Guide)

๐Ÿค Contributing

We welcome contributions! Here's how you can help:

Development Setup

git clone https://github.com/yourorg/fluentyarp.git
cd fluentyarp
dotnet restore
dotnet build
dotnet test

๐Ÿ“Š Performance

Fluent YARP API has zero runtime overhead compared to native YARP. The fluent configuration is converted to native YARP configuration at startup, so there's no performance penalty for the improved developer experience.

๐ŸŒŸ Examples in the Wild

๐Ÿ“‹ Requirements

  • .NET 6.0 or higher
  • Microsoft.Extensions.DependencyInjection
  • Yarp.ReverseProxy

๐Ÿ“ƒ License

This project is licensed under the MIT License - see the LICENSE file for details.

๐Ÿ™ Acknowledgments

  • Built on top of Microsoft YARP
  • Inspired by the need for better developer experience in proxy configuration
  • Thanks to all contributors

<div align="center">

โญ Star this repo if it helped you! โญ

Report Bug โ€ข Request Feature โ€ข Documentation

</div>

Product Compatible and additional computed target framework versions.
.NET net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  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.0.1 111 8/3/2025