ApiGateway is a .NET 8 project that serves as an API Gateway using Ocelot, with integrated JWT authentication and Swagger documentation aggregation.
It routes and secures API requests, providing a unified entry point for downstream services and aggregates Swagger endpoints for easier API exploration.
- Get the Static Api Key from the Frontend
- Use the Api Key https://github.com/VentixeEventManagement/JwtAuthProvider on the JWT Token Provider to get a JWT Token
- Use that Token in swagger by pasting in just the token value or as a header with the Bearer Prefix
- The other microservices are avaliable to be access directly though in the future should be isolated on a private network(azure) and only allow access from the gateway endpoint.
flowchart TD
Start([Start]) --> UserCall[User calls JwtAuthProvider]
UserCall --> CheckAPIKey{Is API Key valid?}
CheckAPIKey -- No --> Reject1[Reject Request]
CheckAPIKey -- Yes --> GenerateJWT[Generate JWT Token]
GenerateJWT --> UseJWT[User calls API Gateway with JWT]
UseJWT --> CheckJWT{Is JWT valid?}
CheckJWT -- No --> Reject2[Reject Request]
CheckJWT -- Yes --> RouteMicroservice[Route to Microservice]
RouteMicroservice --> End([End])
- 🚦 API Gateway using ASP.NET Core & Ocelot
- 🔐 JWT-based Authentication & Authorization for secure access
- 📚 Aggregated Swagger UI for all downstream services (via SwaggerForOcelot)
- 🛣️ Customizable Routing via
ocelot.json - 🧩 Extensible Architecture (custom interceptors & repositories)
-
Clone the repository:
git clone <repo-url>
-
Configure environment variables and update
appsettings.jsonandocelot.jsonfor your environment and downstream services. -
Restore NuGet packages and build:
- Using Visual Studio 2022 or
- With the .NET CLI:
dotnet restore dotnet build
-
Run the project:
- By default, the gateway is accessible at
/gateway
- By default, the gateway is accessible at
-
Access Swagger UI:
- Browse to
/gateway/swaggerto explore and test the aggregated APIs.
- Browse to
ApiGateway/
├── Controllers/ # API controllers for gateway operations
├── Repository/ # Interfaces & implementations for Swagger endpoint data
├── Security/ # JWT authentication services
├── Startup.cs # Configures services, authentication, Swagger, Ocelot
├── Program.cs # Application entry point
├── ocelot.json # Ocelot routing & downstream services config
├── appsettings.json # Application configuration
└── ApiGateway.Tests/ # Integration & unit tests
- Integration and unit tests are in the ApiGateway.Tests project.
- Use your preferred test runner:
dotnet test - Ensure all gateway features and routes function as expected.
- .NET 8 SDK
- Visual Studio 2022 (recommended)
- Downstream services with Swagger/OpenAPI documentation
- Based on the MMLib.SwaggerForOcelot Demo.
- Uses Ocelot for API Gateway features.
This project is provided as-is for demonstration and educational purposes.
Please review and update the license as appropriate for your use case.