Overview
The YARP API Gateway uses route configuration to match incoming requests and transform paths before forwarding to backend services.Route Configuration
Routes are defined in theReverseProxy.Routes section of appsettings.json:
Route Components
1. Route Identifier
Each route has a unique identifier (e.g.,catalog-route, basket-route):
- Configuration reference
- Logging and diagnostics
- Route identification in middleware
2. Cluster Assignment
TheClusterId property links the route to a backend cluster:
3. Match Conditions
TheMatch object defines criteria for route selection:
4. Transformations
TheTransforms array modifies requests before forwarding:
Path Matching
Catch-All Pattern
The{**catch-all} pattern matches zero or more path segments:
Pattern Syntax
| Pattern | Description | Example |
|---|---|---|
/exact | Exact match | /catalog-service only |
/prefix/{*path} | Single-segment catch-all | /prefix/segment |
/prefix/{**path} | Multi-segment catch-all | /prefix/seg1/seg2/seg3 |
/prefix/{id} | Single parameter | /prefix/123 |
/prefix/{id}/suffix | Parameter with suffix | /prefix/123/suffix |
Path Transformation
How It Works
Path transformation strips the service prefix before forwarding:Transform Configuration
PathPattern: The pattern used to construct the forwarded path{**catch-all}: Placeholder replaced with captured path segments
Transformation Examples
Example 1: Product List
Example 2: Specific Product
Example 3: Root Path
Example 4: POST with Body
Complete Routing Flow
Catalog Service Example
Advanced Path Transformations
Adding a Prefix
Path Removal
Static Path
Path Value Substitution
Header Transformations
YARP can also transform headers:Adding Headers
Removing Headers
Query String Handling
Query strings are automatically preserved and forwarded:Query String Transformations
HTTP Method Matching
By default, all HTTP methods are matched. To restrict:Request Header Matching
Route Priority
YARP evaluates routes in configuration order. UseOrder property for explicit prioritization:
Order values are evaluated first.
Route Testing
Using curl
Using Browser DevTools
Common Routing Patterns
API Versioning
Service-Specific Endpoints
Microservice-to-Microservice
Troubleshooting
Route Not Matching
- Check path exactly: Routes are case-sensitive by default
- Verify trailing slash:
/catalog-service/vs/catalog-service - Check route order: More specific routes should come first
- Enable logging: Set
"Yarp": "Debug"in logging configuration
Path Transform Issues
- Missing catch-all: Ensure
{**catch-all}is in both Match and Transform - Double slashes: Check for
//in transformed paths - Query strings: Verify they’re being preserved
Debugging Routes
Enable detailed YARP logging:Related Documentation
- YARP Configuration - Complete proxy configuration
- Rate Limiting - Request throttling
- Overview - API Gateway architecture
