Configuration Overview
YARP (Yet Another Reverse Proxy) is configured through theappsettings.json file under the ReverseProxy section. The configuration defines routes (how to match incoming requests) and clusters (where to forward them).
Configuration Structure
Complete Production Configuration
Here’s the completeappsettings.json used in Docker deployments:
Local Development Configuration
For local development (appsettings.Local.json), the cluster addresses use localhost:
Configuration Elements
Routes
Routes define how incoming requests are matched and forwarded.Route Properties
| Property | Type | Description | Example |
|---|---|---|---|
ClusterId | string | References the target cluster | "catalog-cluster" |
Match.Path | string | URL path pattern to match | "/catalog-service/{**catch-all}" |
Transforms | array | Path transformations to apply | [{ "PathPattern": "{**catch-all}" }] |
RateLimiterPolicy | string | Rate limiting policy name (optional) | "fixed" |
Path Matching Patterns
The{**catch-all} syntax is a catch-all route parameter that matches:
- Zero or more path segments
- Everything after the prefix
- All HTTP methods (GET, POST, PUT, DELETE, etc.)
/catalog-service/→ matches, catch-all =""/catalog-service/api/v1/products→ matches, catch-all ="api/v1/products"/catalog-service/api/v1/products/123→ matches, catch-all ="api/v1/products/123"
Clusters
Clusters define the backend destinations where requests are forwarded.Cluster Properties
| Property | Type | Description | Example |
|---|---|---|---|
Destinations | object | Collection of destination endpoints | See below |
Destinations.{name}.Address | string | Backend service URL | "http://catalog.api:8080" |
Multiple Destinations (Load Balancing)
YARP supports multiple destinations per cluster for load balancing:Loading Configuration in Code
The configuration is loaded inProgram.cs:
- Reads the
ReverseProxysection from configuration - Parses routes and clusters
- Validates the configuration
- Registers YARP services with dependency injection
Configuration Validation
YARP validates configuration at startup and will fail if:- A route references a non-existent cluster
- Required properties are missing
- Path patterns are invalid
- Destination addresses are malformed
Environment-Specific Configuration
Configuration File Priority
ASP.NET Core loads configuration in this order (later overrides earlier):appsettings.json(base configuration)appsettings.{Environment}.json(environment-specific)- User secrets (development only)
- Environment variables
- Command-line arguments
Environment Detection
The environment is set via theASPNETCORE_ENVIRONMENT variable:
Development→ loadsappsettings.Development.jsonProduction→ usesappsettings.json- Custom environments → loads
appsettings.{Custom}.json
Route Ordering
YARP evaluates routes in the order they appear in configuration. More specific routes should be defined before general ones. Current Route Order:catalog-route-/catalog-service/{**catch-all}basket-route-/basket-service/{**catch-all}ordering-route-/ordering-service/{**catch-all}
Advanced Configuration Options
Health Checks
Metadata
HTTP Client Configuration
Configuration Hot Reload
YARP supports configuration hot reload. Changes toappsettings.json are automatically detected and applied without restarting the application.
Note: In Docker containers, the configuration file is copied at build time, so hot reload requires volume mounting:
Related Documentation
- Rate Limiting - Request throttling configuration
- Routing - Route matching and transformations
- Overview - API Gateway architecture
