Aspire.Hosting.Yarp 13.6.4

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

YARP hosting integration

Use this integration to model, configure, and orchestrate a YARP reverse proxy instance in an Aspire solution.

Getting started

Add the integration

From your AppHost directory, add the Aspire.Hosting.Yarp integration with the Aspire CLI:

aspire add 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 bind mounts files in run mode and copies them into the generated container image in publish mode.

Copy files via Docker

You can also use a Dockerfile to copy static assets into the YARP container. Pass the YARP base image used by your deployment as YARP_BASE_IMAGE when building the image:

var yarpBaseImage = builder.AddParameter("yarp-base-image");

builder.AddYarp("frontend")
       .WithStaticFiles()
       .WithDockerfile("../npmapp")
       .WithBuildArg("YARP_BASE_IMAGE", yarpBaseImage);
# 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 into the YARP base image used by your deployment
ARG YARP_BASE_IMAGE
FROM ${YARP_BASE_IMAGE} 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");
       });

Terminate TLS and proxy h2c (for gRPC)

var grpcBackend = builder.AddProject<Projects.GrpcBackend>("grpc-backend");

builder.AddYarp("gateway")
    .WithHostHttpsPort(8080)
    .WithConfiguration(yarp =>
    {
        var cluster = yarp.AddCluster(grpcBackend.GetEndpoint("http"))
            .WithForwarderRequestConfig(new ForwarderRequestConfig
            {
                Version = HttpVersion.Version20,
                VersionPolicy = HttpVersionPolicy.RequestVersionExact,
            });
        yarp.AddRoute(cluster);
    });

The grpcBackend resource must expose an http endpoint and be configured to accept HTTP/2 without TLS (h2c). Passing its endpoint reference lets Aspire resolve an address that is reachable from the YARP container. Aspire uses the local development certificate for TLS termination when it is available. For certificate setup or trust issues, see https://aka.ms/aspire/devcerts.

Additional documentation

Feedback & contributing

https://github.com/microsoft/aspire

Product 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (2)

Showing the top 2 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.

Trifork.Aspire.Hosting.Corax

Aspire hosting integration that runs Corax Core and its dependencies locally.

GitHub repositories (6)

Showing the top 6 popular GitHub repositories that depend on Aspire.Hosting.Yarp:

Repository Stars
dotnet/eShop
A reference .NET application implementing an eCommerce site
foxminchan/BookWorm
An Aspire reference architecture for cloud-native microservices and agentic AI with MCP, A2A & AG-UI
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
nightscout/nocturne
A next-generation platform for diabetes management
davidfowl/aspire-ssh-deploy
An extension of the docker compose integration for deploying to a docker host via SSH
Version Downloads Last Updated
13.6.4 2,588 10/24/2026
13.6.3 2,233 10/21/2026
13.6.2 1,679 10/20/2026
13.6.1 16,257 10/7/2026
13.6.0 22,962 9/29/2026
13.5.4 24,964 9/15/2026
13.5.3 31,144 8/25/2026
13.5.2 12,136 8/21/2026
13.5.1 2,414 8/20/2026
13.5.0 7,060 8/18/2026
13.4.6 89,851 6/19/2026
13.4.5 7,084 6/17/2026
13.4.4 6,692 6/15/2026
13.4.3 16,151 6/8/2026
13.4.2 8,009 6/3/2026
13.4.1 3,033 6/3/2026
13.4.0 7,351 6/1/2026
13.3.5 19,892 5/21/2026
13.3.4 4,655 5/19/2026
13.3.3 9,441 5/15/2026
Loading failed