gitmyhub

Ocelot

C# ★ 8.7k updated 23h ago

.NET API Gateway

Ocelot is a .NET API gateway library that routes all client requests through a single entry point, with built-in authentication, rate limiting, caching, and load balancing across your backend services.

C#.NETASP.NET Coresetup: moderatecomplexity 4/5

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.

Where it fits