Configs2026年5月23日·1 分钟阅读

YARP — High-Performance Reverse Proxy Toolkit for .NET

A toolkit for building fast, customizable reverse proxy servers in .NET using the ASP.NET Core infrastructure, developed by Microsoft.

Agent 就绪

这个资产可以被 Agent 直接读取和安装

TokRepo 同时提供通用 CLI 命令、安装契约、metadata JSON、按适配器生成的安装计划和原始内容链接,方便 Agent 判断适配度、风险和下一步动作。

Native · 98/100策略:允许
Agent 入口
任意 MCP/CLI Agent
类型
Skill
安装
Single
信任
信任等级:Established
入口
YARP Overview
通用 CLI 安装命令
npx tokrepo install cfa49c19-56c4-11f1-9bc6-00163e2b0d79

Introduction

YARP (Yet Another Reverse Proxy) is a library for building reverse proxy servers in .NET. Unlike standalone proxy binaries, YARP runs as middleware inside an ASP.NET Core application, giving developers full control over routing, transforms, and load balancing through code and configuration.

What YARP Does

  • Routes incoming HTTP requests to backend clusters based on path, headers, or query strings
  • Balances load across multiple destination servers with built-in algorithms
  • Transforms request and response headers, paths, and query strings
  • Supports health checking to remove unhealthy backends from rotation
  • Enables session affinity for stateful backend services

Architecture Overview

YARP runs as ASP.NET Core middleware in the request pipeline. It reads route and cluster configuration from appsettings.json, code, or custom providers. For each incoming request, YARP matches it to a route, selects a destination from the cluster using load balancing, applies request transforms, forwards the call via HttpClient, and applies response transforms on the way back. The entire pipeline is async and uses Kestrel for high-throughput proxying.

Self-Hosting & Configuration

  • Install via NuGet: dotnet add package Yarp.ReverseProxy
  • Define routes and clusters in appsettings.json or via code-based configuration
  • Add health check endpoints to automatically remove failing backends
  • Apply request/response transforms for header rewriting and path modification
  • Supports dynamic configuration providers that reload without restart

Key Features

  • Code-level extensibility through ASP.NET Core middleware pipeline
  • Multiple load balancing algorithms: round robin, least requests, random, power of two choices
  • Active and passive health checking with configurable thresholds
  • Header, path, and query string transforms without custom code
  • Direct HTTP/2 and gRPC proxying support

Comparison with Similar Tools

  • Nginx — standalone reverse proxy written in C; more mature, less programmable from .NET
  • Envoy — cloud-native L7 proxy; broader feature set, requires sidecar deployment
  • Traefik — auto-discovery reverse proxy; strong Docker/K8s integration, not embeddable in .NET
  • HAProxy — high-performance TCP/HTTP proxy; battle-tested, no .NET integration
  • Ocelot — .NET API gateway; similar concept but older architecture, less active development

FAQ

Q: When should I use YARP instead of Nginx or Traefik? A: Use YARP when you need to embed proxy logic inside a .NET application, apply custom C# transforms, or integrate with existing ASP.NET Core middleware like authentication and rate limiting.

Q: Can YARP handle gRPC traffic? A: Yes. YARP supports proxying HTTP/2 traffic including gRPC without additional configuration.

Q: Does YARP support dynamic configuration changes? A: Yes. YARP provides an IProxyConfigProvider interface for custom configuration sources and supports live reload without application restart.

Q: How does YARP compare to Ocelot? A: YARP is developed by Microsoft, uses modern ASP.NET Core primitives, and targets high-throughput scenarios. Ocelot is a community project with a broader feature set for API gateway patterns but uses an older architecture.

Sources

讨论

登录后参与讨论。
还没有评论,来写第一条吧。

相关资产