This repository demonstrates how to build API Gateways using two different .NET technologies:
ApiGateway.Ocelot.RestApi
– Implements a gateway using Ocelot, a lightweight API gateway library for .NET.ApiGateway.Yarp.RestApi
– Implements a gateway using YARP (Yet Another Reverse Proxy), a modern, high-performance reverse proxy from Microsoft.
Both projects show how to route multiple REST APIs through a single gateway endpoint and support multiple downstream services.
- Email: vishwa@vishwa.me
- GitHub: Vishwam
- LinkedIn: Vishwa Kumar
Vishwa is the primary developer and architect of this example app, responsible for the architecture and implementation of these features.
This project is licensed under the MIT License - see the LICENSE file for details.
- Centralized routing for multiple REST APIs
- Aggregated Swagger UI (in YARP)
- Easily extendable to support more downstream services
- Minimal configuration required to onboard new APIs
Ocelot is configured via ocelot.json
and uses route-based forwarding to downstream services. Swagger endpoints are aggregated using the SwaggerKey
and SwaggerEndPoints
config.
- Example upstream routes:
/apiaudit/api/{everything}
→https://restaudit.azurewebsites.net/api/{everything}
/hourtracker/api/{everything}
→https://hourtrackerrest.azurewebsites.net/api/{everything}
YARP is configured via appsettings.json
and uses a declarative model for routes and clusters. Swagger UI is hosted centrally in the gateway and proxies each downstream's Swagger JSON.
- Swagger UI available at:
https://localhost:7153/swagger/index.html
- Example upstream routes:
/apiaudit/api/{*}
→https://restaudit.azurewebsites.net/api/{*}
/hourtracker/api/{*}
→https://hourtrackerrest.azurewebsites.net/api/{*}
- Aggregated Swagger JSONs:
/apiaudit/swagger/v1/swagger.json
/hourtracker/swagger/v1/swagger.json
- .NET SDK 9.0 or later
- Visual Studio or VS Code
- Two backend REST APIs (or mock endpoints)
dotnet run --project ApiGateway.Ocelot.RestApi