Intro To YARP In C# - How To Create a Reverse Proxy
When it comes to managing web traffic efficiently in a .NET Core environment, a reverse proxy becomes an indispensable tool. YARP, short for Yet Another Reverse Proxy, is Microsoft's highly flexible and highly customizable reverse proxy project built specifically for the .NET ecosystem. In this article, we’re going to dive deep into getting started with YARP by following Tim Corey’s comprehensive tutorial on "Intro To YARP In C# - How To Create a Reverse Proxy", where he demonstrates setting up and using YARP in a .NET Core web application.
Let’s begin with an introduction to YARP, and how you can leverage this proxy framework in your own projects.
What is a Reverse Proxy?
At 1:07, Tim explains that a reverse proxy sits between the client (users) and the backend servers, managing the incoming requests and efficiently routing requests to the appropriate destination.
Tim at 1:45 outlines why a proxy is important: not only for load balancing but also for simplifying request headers, securing connections with HTTPS, and ensuring that backend services are isolated from direct access. By using a reverse proxy, you can scale your net core applications easily without exposing your internal structure.
Introduction to YARP
At 5:11, Tim introduces YARP — Yet Another Reverse Proxy. Tim explains that Microsoft realized the need for a proxy framework that was better suited for the specific needs of their wide range of .NET applications, leading to the creation of YARP. It’s designed to be a library that provides the core proxy functionality in a way that is modular, robust, and extensible.
This library is under active development, ensuring it includes the latest features and supports the latest technologies like Linux, Windows, and cloud environments.
Additionally, Tim emphasizes the comprehensive maintained documentation and extensive documentation available for YARP, which makes getting started much easier for new developers.
Setting up a Basic YARP Project
At 6:14, Tim starts a new project in Visual Studio using the net SDK. He creates a basic ASP.NET Core Web API project named Pessimistic API.
Tim at 7:02 modifies the project to create a Pessimistic API that simulates a cold weather service. This simple net core application is the backend server that YARP will later proxy to.
Tim suggests at 8:44 verifying the project before moving forward, ensuring the example service responds correctly to requests at /weatherforecast.
Creating the YARP Gateway
At 9:04, Tim creates an empty ASP.NET Core project called YarpGateway. This project acts as the reverse proxy.
Tim walks through installing the necessary package by going to Manage NuGet Packages and searching for install package YARP (at 10:24). This pulls in YARP Reverse Proxy, the official library that provides the needed core proxy functionality.
Configuring YARP
At 12:02, Tim demonstrates how to wire up YARP configuration inside Program.cs by using:
builder.Services.AddReverseProxy().LoadFromConfig(builder.Configuration.GetSection("YARP"));
builder.Services.AddReverseProxy().LoadFromConfig(builder.Configuration.GetSection("YARP"));
This setup loads configuration files that define the routes and clusters — fundamental elements when using YARP for routing requests.
Routes match the incoming path, and clusters define the backend services to forward to. This modular configuration supports adding advanced features like rate limiting, replacing modules, and fine-tuning path management.
Tim points out that this flexible design is why YARP is a highly customizable reverse proxy suited for real-world projects.
Testing the Basic Proxy Setup
At 20:02, Tim shows running both the backend Pessimistic API and the YarpGateway together.
When you navigate to the gateway’s URL /weatherforecast, YARP routes the incoming request to the backend server, fetches the response, and serves it — without exposing the internal URL. This demonstrates proxy functionality and routing requests in action.
Expanding with a Second Backend
At 21:17, Tim adds another new project called Optimistic API which returns only warm temperatures.
He configures YARP with multiple destinations within a single cluster. This enables load balancing — distributing incoming requests randomly between two backend servers.
Later, at 26:26, Tim explains that you can further customize the load balancing strategy, including options like round robin or custom logic based on request attributes.
Upgrading a Static Website with YARP
At 28:12, Tim describes a real-world example: upgrading his own website (iamtimcorey.com).
He creates a WebsiteUpgrade net core web application that proxies all traffic to the original site using a catch-all route.
This strategy allows for incremental updates: Tim can rebuild and modernize pages using Razor while still supporting older content served by the legacy system. Incoming requests are automatically routed either to the original site or to the new content, depending on the path.
Adding New Functionality with Razor Pages
At 34:30, Tim adds Razor Pages into the upgrade project. He shows how to add a simple page (/more) that is served directly by the new application while everything else is proxied.
Thanks to YARP’s flexibility, new modules and features can be added without disturbing existing backend services.
Implementing Advanced Routing and Path Transforms
At 39:03, Tim builds a /random route that rewrites the path and redirects users randomly among three different course pages.
He uses YARP’s transforms feature to modify request headers and paths during proxying, showing how developers can fine-tune the behavior for specific needs.
Tim encounters a typo around 44:03 but corrects it, emphasizing careful attention to configuration files.
Setting Up Round Robin Load Balancing
At 45:10, Tim switches the random routing to round robin. This simple configuration change improves predictability in distributing traffic between multiple pages.
It highlights one of the key characteristics of YARP: the ease of customizing behaviors dynamically through configuration alone, without deep code changes.
Conclusion: Why Choose YARP?
At 47:03, Tim wraps up by summarizing why YARP is a critical tool for modern net core applications:
It’s designed as a library for easy integration.
It provides the core proxy functionality developers need.
It is under active development by Microsoft.
It supports Linux, Windows, and HTTPS out of the box.
It has extensive documentation and comprehensive maintained documentation.
It allows routing requests flexibly to multiple backend servers.
It supports easy customization for specific needs.
- It’s production-grade, scalable, and tuned for performance.
Tim encourages viewers to explore even more features, like rate limiting, replacing modules, and deeper API gateway setups, by following the official docs or suggesting a full YARP course.
Final Thoughts
By following Tim Corey’s complete video of setting up a YARP Reverse Proxy, any developer can quickly get up to speed with yet another reverse proxy. Whether you are handling complex load balancing, replacing modules, or incrementally upgrading your site, YARP Yet Another Reverse Proxy offers a solid, flexible solution for the net core world. Do check out his YouTube Channel for more insightful videos.