FluentYarp 1.0.1
dotnet add package FluentYarp --version 1.0.1
NuGet\Install-Package FluentYarp -Version 1.0.1
<PackageReference Include="FluentYarp" Version="1.0.1" />
<PackageVersion Include="FluentYarp" Version="1.0.1" />
<PackageReference Include="FluentYarp" />
paket add FluentYarp --version 1.0.1
#r "nuget: FluentYarp, 1.0.1"
#:package FluentYarp@1.0.1
#addin nuget:?package=FluentYarp&version=1.0.1
#tool nuget:?package=FluentYarp&version=1.0.1
Fluent YARP API ๐
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
- Complete Developer Guide - Comprehensive documentation with examples
- API Reference - Full interface documentation
- Migration Guide - Convert from JSON configuration
- Best Practices - Performance and security guidelines
- Examples - Real-world usage examples
๐ ๏ธ 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:
- ๐ Report bugs - Open an issue
- ๐ก Request features - Start a discussion
- ๐ง Submit PRs - See our Contributing Guide
- ๐ Improve docs - Help make the documentation better
- โญ Star the repo - Show your support!
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
- E-commerce Platform: See examples/ecommerce for a complete microservices setup
- Multi-tenant SaaS: Check examples/multitenant for tenant-based routing
- API Gateway: Browse examples/api-gateway for enterprise patterns
๐ 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 | Versions 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. |
-
net9.0
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 9.0.0)
- Microsoft.Extensions.Hosting.Abstractions (>= 9.0.0)
- Microsoft.Extensions.ServiceDiscovery.Yarp (>= 9.4.0)
- Yarp.ReverseProxy (>= 2.3.0)
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 |