Recently I was wiring up a YARP reverse proxy in front of a couple of Aspire-managed services: an API and an Angular frontend. Aspire gives you service discovery for free, so the obvious move is to point your YARP clusters at the logical service names instead of hardcoded URLs.
My first attempt looked like this:
"Clusters": {
"api-cluster": {
"Destinations": {
"api-destination": {
"Address": "https+http://api"
}
}
},
"frontend-cluster": {
"Destinations": {
"frontend-destination": {
"Address": "https+http://angular-frontend"
}
}
}
}
The https+http:// scheme is the standard Aspire service discovery convention: try HTTPS first, fall back to HTTP. It works fine when you're resolving endpoints through HttpClient.
Unfortunately YARP doesn’t like this configuration. After setting it up with these values I got the following error back:
The https+http scheme is not supported
YARP's own configuration binder doesn't understand the + scheme syntax on its own. It expects a destination address it can use directly. Service discovery resolution is a separate concern, and YARP needs to be told explicitly to run destinations through it.
Remark: If you are looking for an end-2-end example on how to setup YARP with Aspire, check out this blog post by Tim Deschryver: Using YARP as BFF within .NET Aspire: Integrating YARP into .NET Aspire.
The fix
Add the Microsoft.Extensions.ServiceDiscovery.Yarp package:
dotnet add package Microsoft.Extensions.ServiceDiscovery.Yarp
Then wire up service discovery and hook it into YARP's destination resolution in Program.cs:
builder.Services.AddServiceDiscovery();
builder.Services.AddReverseProxy()
.LoadFromConfig(builder.Configuration.GetSection("ReverseProxy"))
.AddServiceDiscoveryDestinationResolver();
AddServiceDiscoveryDestinationResolver() is the piece that makes YARP understand https+http:// addresses. It plugs service discovery into YARP's destination resolution pipeline, so the same appsettings.json cluster config you started with just works:
"Clusters": {
"api-cluster": {
"Destinations": {
"api-destination": {
"Address": "https+http://api"
}
}
},
"frontend-cluster": {
"Destinations": {
"frontend-destination": {
"Address": "https+http://angular-frontend"
}
}
}
}
No config changes needed once the resolver is registered. The Address values were correct from the start, YARP just needed to be told how to interpret them.
Remark: if you're using YARP's direct forwarding (IHttpForwarder) instead of the full proxy pipeline, the equivalent call is AddHttpForwarderWithServiceDiscovery() on the service collection, not the resolver extension above.
That's it. One package, one extension method, and the scheme error disappears.