Aspire.Hosting.Yarp
13.4.6
Prefix Reserved
dotnet add package Aspire.Hosting.Yarp --version 13.4.6
NuGet\Install-Package Aspire.Hosting.Yarp -Version 13.4.6
<PackageReference Include="Aspire.Hosting.Yarp" Version="13.4.6" />
<PackageVersion Include="Aspire.Hosting.Yarp" Version="13.4.6" />
<PackageReference Include="Aspire.Hosting.Yarp" />
paket add Aspire.Hosting.Yarp --version 13.4.6
#r "nuget: Aspire.Hosting.Yarp, 13.4.6"
#:package Aspire.Hosting.Yarp@13.4.6
#addin nuget:?package=Aspire.Hosting.Yarp&version=13.4.6
#tool nuget:?package=Aspire.Hosting.Yarp&version=13.4.6
Aspire.Hosting.Yarp library
Provides extension methods and resource definitions for an Aspire AppHost to configure a YARP reverse proxy instance.
Getting started
Install the package
In your AppHost project, install the Aspire YARP Hosting library with NuGet:
dotnet add package Aspire.Hosting.Yarp
Usage examples
Programmatic configuration
The modern approach uses programmatic configuration with the WithConfiguration method:
var builder = DistributedApplication.CreateBuilder(args);
var backendService = builder.AddProject<Projects.Backend>("backend");
var frontendService = builder.AddProject<Projects.Frontend>("frontend");
var gateway = builder.AddYarp("gateway")
.WithConfiguration(yarp =>
{
// Add a catch-all route for the frontend
yarp.AddRoute(frontendService);
// Add a route with path prefix for the backend API
yarp.AddRoute("/api/{**catch-all}", backendService)
.WithTransformPathRemovePrefix("/api");
});
var app = builder.Build();
await app.RunAsync();
Configuration with external services
You can also route to external services:
var externalApi = builder.AddExternalService("external-api", "https://api.example.com");
var gateway = builder.AddYarp("gateway")
.WithConfiguration(yarp =>
{
yarp.AddRoute("/external/{**catch-all}", externalApi)
.WithTransformPathRemovePrefix("/external");
});
Static file serving
YARP can serve static files alongside proxied routes. There are two approaches:
Copy files locally
builder.AddYarp("static")
.WithStaticFiles("../static");
This will copy files into the container use container files in run mode, and use a bind mount in publish mode.
Copy files via Docker
You can also use a docker file to copy static assets into the yarp container: e.g.
builder.AddYarp("frontend")
.WithStaticFiles()
.WithDockerFile("../npmapp");
# Stage 1: Build React app
FROM node:20 AS builder
WORKDIR /app
COPY . .
RUN npm install
RUN npm run build
# Stage 2: Copy static files to YARP container
FROM mcr.microsoft.com/dotnet/nightly/yarp:2.3.0-preview.4 AS yarp
WORKDIR /app
COPY --from=builder /app/dist ./wwwroot
Configuration API
Route configuration
The IYarpConfigurationBuilder provides methods to configure routes and clusters:
// Add routes with different targets
yarp.AddRoute(resource); // Catch-all route
yarp.AddRoute("/path/{**catch-all}", resource); // Specific path route
yarp.AddRoute("/path/{**catch-all}", endpoint); // Route to specific endpoint
yarp.AddRoute("/path/{**catch-all}", externalService); // Route to external service
// Add clusters directly
var cluster = yarp.AddCluster(resource);
var route = yarp.AddRoute("/path/{**catch-all}", cluster);
Route matching options
Routes can be configured with various matching criteria:
yarp.AddRoute("/api/{**catch-all}", backendService)
.WithMatchMethods("GET", "POST") // HTTP methods
.WithMatchHeaders(new RouteHeader("Content-Type", "application/json")) // Headers
.WithMatchHosts("api.example.com") // Host header
.WithOrder(1); // Route priority
Transform extensions
YARP provides various transform extensions to modify requests and responses:
Path transforms
route.WithTransformPathSet("/new/path") // Set path
.WithTransformPathPrefix("/prefix") // Add prefix
.WithTransformPathRemovePrefix("/api") // Remove prefix
.WithTransformPathRouteValues("/users/{id}/posts"); // Use route values
Request header transforms
route.WithTransformRequestHeader("X-Forwarded-For", "value") // Add/set header
.WithTransformRequestHeaderRouteValue("X-User-Id", "id") // From route value
.WithTransformUseOriginalHostHeader(true) // Preserve host
.WithTransformCopyRequestHeaders(false); // Copy headers
Response transforms
route.WithTransformResponseHeader("X-Powered-By", "Aspire") // Add response header
.WithTransformResponseHeaderRemove("Server") // Remove header
.WithTransformCopyResponseHeaders(true); // Copy headers
Query parameter transforms
route.WithTransformQueryValue("version", "1.0") // Add query param
.WithTransformQueryRouteValue("userId", "id") // From route value
.WithTransformQueryRemoveKey("debug"); // Remove query param
Advanced configuration
Multiple routes to the same service
builder.AddYarp("gateway")
.WithConfiguration(yarp =>
{
// Different routes to the same backend
yarp.AddRoute("/api/v1/{**catch-all}", backendService)
.WithTransformPathRemovePrefix("/api/v1");
yarp.AddRoute("/api/v2/{**catch-all}", backendService)
.WithTransformPathRemovePrefix("/api/v2")
.WithTransformPathPrefix("/v2");
});
Additional documentation
Feedback & contributing
https://github.com/microsoft/aspire
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. 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. |
-
net8.0
- Aspire.Hosting (>= 13.4.6)
- AspNetCore.HealthChecks.Uris (>= 9.0.0)
- Google.Protobuf (>= 3.34.1)
- Grpc.AspNetCore (>= 2.80.0)
- Grpc.Net.ClientFactory (>= 2.80.0)
- Grpc.Tools (>= 2.80.0)
- Humanizer.Core (>= 3.0.10)
- JsonPatch.Net (>= 3.3.0)
- KubernetesClient (>= 19.0.2)
- Microsoft.Extensions.Configuration.Abstractions (>= 10.0.8)
- Microsoft.Extensions.Configuration.Binder (>= 10.0.8)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.8)
- Microsoft.Extensions.Diagnostics.HealthChecks (>= 8.0.27)
- Microsoft.Extensions.FileSystemGlobbing (>= 10.0.8)
- Microsoft.Extensions.Hosting (>= 10.0.8)
- Microsoft.Extensions.Hosting.Abstractions (>= 10.0.8)
- Microsoft.Extensions.Http (>= 10.0.8)
- Microsoft.Extensions.Logging (>= 10.0.8)
- Microsoft.Extensions.Logging.Abstractions (>= 10.0.8)
- Microsoft.Extensions.Options (>= 10.0.8)
- Microsoft.Extensions.Primitives (>= 10.0.8)
- ModelContextProtocol (>= 1.3.0)
- Newtonsoft.Json (>= 13.0.4)
- OpenTelemetry.Exporter.OpenTelemetryProtocol (>= 1.15.3)
- OpenTelemetry.Extensions.Hosting (>= 1.15.3)
- Polly.Core (>= 8.6.6)
- Semver (>= 3.0.0)
- StreamJsonRpc (>= 2.25.29)
- System.IO.Hashing (>= 10.0.8)
- System.Text.Json (>= 10.0.8)
- Yarp.ReverseProxy (>= 2.3.0)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Aspire.Hosting.Yarp:
| Package | Downloads |
|---|---|
|
NapalmCodes.Aspire.Hosting.Krakend
Aspire hosting component for the high performance KrakenD (https://www.krakend.io/) API Gateway. |
GitHub repositories (5)
Showing the top 5 popular GitHub repositories that depend on Aspire.Hosting.Yarp:
| Repository | Stars |
|---|---|
|
dotnet/eShop
A reference .NET application implementing an eCommerce site
|
|
|
foxminchan/BookWorm
The practical implementation of Aspire using Microservices, AI-Agents
|
|
|
davidfowl/aspire-ai-chat-demo
Aspire AI Chat is a full-stack chat sample that combines modern technologies to deliver a ChatGPT-like experience.
|
|
|
daohainam/microservice-patterns
Microservice pattern demos (Saga, EventSourcing, CQRS...) running on .NET Aspire
|
|
|
davidfowl/aspire-ssh-deploy
An extension of the docker compose integration for deploying to a docker host via SSH
|
| Version | Downloads | Last Updated |
|---|---|---|
| 13.4.6 | 16,845 | 6/19/2026 |
| 13.4.5 | 3,029 | 6/17/2026 |
| 13.4.4 | 3,754 | 6/15/2026 |
| 13.4.3 | 8,769 | 6/8/2026 |
| 13.4.2 | 5,172 | 6/3/2026 |
| 13.4.1 | 1,142 | 6/3/2026 |
| 13.4.0 | 4,342 | 6/1/2026 |
| 13.3.5 | 13,544 | 5/21/2026 |
| 13.3.4 | 2,788 | 5/19/2026 |
| 13.3.3 | 6,992 | 5/15/2026 |
| 13.3.2 | 4,959 | 5/14/2026 |
| 13.3.1 | 3,152 | 5/12/2026 |
| 13.3.0 | 12,380 | 5/7/2026 |
| 13.2.4 | 15,627 | 4/24/2026 |
| 13.2.3 | 4,647 | 4/21/2026 |
| 13.2.2 | 22,577 | 4/8/2026 |
| 13.2.1 | 10,326 | 3/31/2026 |
| 13.2.0 | 22,187 | 3/23/2026 |
| 13.1.3 | 4,278 | 3/19/2026 |
| 13.1.2 | 25,548 | 2/26/2026 |