Add a unified API gateway to a .NET microservices app that routes requests to different backend services based on the URL path.
Rate limit a public API endpoint so individual clients cannot exceed a set number of requests per period.
Load balance traffic across multiple instances of a backend service without changing any client code.
Aggregate responses from several microservices into a single combined API response.
Requires a .NET 8 or 9 project. Install via NuGet and provide an ocelot.json route configuration file.
Ocelot is an API gateway library for .NET applications. An API gateway sits in front of a set of backend services and acts as the single door that all client requests pass through. Instead of a client calling ten different services at different addresses, it calls one address (the gateway), and the gateway decides which backend service to forward each request to, then passes the response back. Ocelot is aimed at developers building microservices in .NET who want this kind of unified entry point. Technically, Ocelot is built as a chain of ASP.NET Core middleware components. Each incoming request is processed step by step through the chain: the gateway reads its configuration, matches the request to a route definition, optionally transforms headers or query strings, then forwards the request to the appropriate downstream service over HTTP. The response comes back through the same chain and is returned to the original caller. The feature set covers the main concerns of a gateway. Routing and configuration are the core pieces: you define in a JSON file which incoming paths map to which backend URLs. Beyond that, Ocelot supports authentication (it integrates with OAuth2/Bearer tokens), rate limiting to cap how many requests a client can make in a period, response caching, load balancing across multiple instances of a service, and aggregation (combining responses from multiple services into one reply). Service discovery integrations let the gateway find backend addresses dynamically rather than hard-coding them. Ocelot is installed from NuGet (dotnet add package Ocelot) and supports .NET 8 and .NET 9. It is MIT licensed and maintained as an active open-source project with full documentation on Read the Docs.
← threemammals on gitmyhub — every repo by this author, as a profile.
Verify against the repo before relying on details.