Ocelot API Gateway¶
π§ Responsibilities of This Gateway¶
- Request routing to downstream services
- Centralized authentication and authorization
- Rate limiting and request throttling
- API aggregation (where applicable)
- Observability (logging, tracing, correlation IDs)
π« Non-Responsibilities¶
- Business logic
- Data access
- UI rendering
- Certificate or TLS management
- The gateway must remain stateless and thin.
π Security Considerations¶
- Authentication is enforced at the gateway level (e.g., JWT, Entra ID)
- Authorization policies are applied per route
- Secrets and sensitive configuration must be injected via environment variables
- No secrets should be stored in route configuration files
π± Route Configuration Strategy¶
- Route definitions are split by environment to ensure:
- Clear separation of concerns
- Safer production deployments
- Predictable behavior per environment
π Recommended Folder Structure¶
(ASP.NET Core + Ocelot)
This project implements an API Gateway using Ocelot on ASP.NET Core, acting as an internal gateway responsible for routing, aggregation, security enforcement, and observability.
apigateway-ocelot/
β
ββ .vs/ # Visual Studio local settings (not versioned)
β
ββ bin/ # Compiled binaries (generated)
ββ obj/ # Build artifacts (generated)
β
ββ Controllers/ # Optional controllers (health, diagnostics)
β
ββ Properties/
β ββ launchSettings.json # Local launch configuration
β
ββ .dockerignore # Docker ignore rules
ββ .env # Local environment variables (not committed)
ββ .env.sample # Environment variable template
β
ββ ApiGateway.csproj # .NET project definition
ββ ApiGateway.sln # Solution file
β
ββ Dockerfile # Container definition for the gateway
β
ββ Program.cs # Application entry point
ββ Startup.cs # Service registration and middleware
β
ββ README.md # Gateway overview and usage
β
ββ route-local.json # Ocelot routes for local environment
ββ route-dev.json # Ocelot routes for development environment
ββ route-dockercontainer.json # Routes for containerized execution
ββ route-prod.json # Ocelot routes for production