So far I’ve always used ProxyKit to create a reverse proxy in ASP.NET Core. But with the announcement of Yarp, it is time to try this alternative…
- I created a new ASP.NET Core “empty” project:
dotnet new web -n ProxyTest -f netcoreapp3.1
The template "ASP.NET Core Empty" was created successfully.Processing post-creation actions...
Running 'dotnet restore' on ProxyTest\ProxyTest.csproj...
Restore completed in 278,54 ms for C:\Projects\test\yarptest\ProxyTest\ProxyTest.csproj.Restore succeeded.
- Next step is to reference the Microsoft.ReverseProxy preview nuget package:
<ItemGroup> <PackageReference Include="Microsoft.ReverseProxy" Version="1.0.0-preview.1.*" /> </ItemGroup>
- Now it is time to update our Startup.cs. This is what I had when using Proxykit:
- And here is the updated Startup.cs after switching to Yarp:
- In Yarp everything is handled through configuration right now, so the real magic is there:
I'm curious on how this will evolve in the future...