explaingit

threemammals/ocelot

8,701C#Audience · developerComplexity · 4/5LicenseSetup · moderate

TLDR

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.

Mindmap

mindmap
  root((repo))
    What it does
      API gateway
      Request routing
    Features
      Authentication
      Rate limiting
      Load balancing
      Response caching
    Tech Stack
      C# dotNET
      ASP.NET Core
    Configuration
      JSON route config
      Service discovery
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

Things people build with this

USE CASE 1

Add a unified API gateway to a .NET microservices app that routes requests to different backend services based on the URL path.

USE CASE 2

Rate limit a public API endpoint so individual clients cannot exceed a set number of requests per period.

USE CASE 3

Load balance traffic across multiple instances of a backend service without changing any client code.

USE CASE 4

Aggregate responses from several microservices into a single combined API response.

Tech stack

C#.NETASP.NET Core

Getting it running

Difficulty · moderate Time to first run · 30min

Requires a .NET 8 or 9 project. Install via NuGet and provide an ocelot.json route configuration file.

MIT licensed, use freely in personal and commercial projects as long as you include the copyright notice.

In plain English

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.

Copy-paste prompts

Prompt 1
Using threemammals/ocelot, help me write an ocelot.json configuration that routes /users/* to a service at localhost:5001 and /orders/* to a service at localhost:5002.
Prompt 2
I want to add OAuth2 Bearer token authentication to my Ocelot API gateway. Show me the configuration and the middleware setup in ASP.NET Core.
Prompt 3
Using Ocelot, help me configure rate limiting so each client IP is capped at 100 requests per minute across my .NET microservices.
Prompt 4
Help me set up response aggregation in Ocelot to merge results from two downstream services into a single JSON response returned to the client.
Open on GitHub → Explain another repo

← threemammals on gitmyhub — every repo by this author, as a profile.

Verify against the repo before relying on details.