Indiko.Hosting.Gateway
2.1.0
See the version list below for details.
dotnet add package Indiko.Hosting.Gateway --version 2.1.0
NuGet\Install-Package Indiko.Hosting.Gateway -Version 2.1.0
<PackageReference Include="Indiko.Hosting.Gateway" Version="2.1.0" />
<PackageVersion Include="Indiko.Hosting.Gateway" Version="2.1.0" />
<PackageReference Include="Indiko.Hosting.Gateway" />
paket add Indiko.Hosting.Gateway --version 2.1.0
#r "nuget: Indiko.Hosting.Gateway, 2.1.0"
#:package Indiko.Hosting.Gateway@2.1.0
#addin nuget:?package=Indiko.Hosting.Gateway&version=2.1.0
#tool nuget:?package=Indiko.Hosting.Gateway&version=2.1.0
Indiko.Hosting.Gateway
API Gateway hosting implementation using Ocelot for routing, load balancing, and service discovery in microservices architectures.
Overview
This package provides a complete hosting solution for API Gateway applications built on Ocelot, including Consul service discovery integration, request routing, load balancing, and seamless integration with Indiko Blocks.
Features
- Ocelot API Gateway: Full Ocelot integration for API gateway functionality
- Consul Integration: Service discovery using HashiCorp Consul
- Request Routing: Route requests to downstream microservices
- Load Balancing: Distribute requests across multiple service instances
- Forwarded Headers: Support for reverse proxy scenarios with full forwarding
- HTTPS Support: Optional HTTPS redirection
- Configuration-based: Define routes via JSON configuration files
- Dynamic Service Discovery: Automatic service endpoint resolution via Consul
Installation
dotnet add package Indiko.Hosting.Gateway
Quick Start
Minimal Setup
using Indiko.Hosting.Gateway;
// Create your startup class
public class Startup : GatewayStartup
{
public Startup(IConfiguration configuration, IWebHostEnvironment environment)
: base(configuration, environment)
{
}
protected override bool AddControllersWithViews => false;
protected override bool EnableForwardedHeaderOptions => true;
protected override bool ForceHttps => false; // Usually behind load balancer
}
// Program.cs
class Program
{
static async Task<int> Main(string[] args)
{
return await GatewayHostBootstrapper.Instance.RunAsync<Startup>(args);
}
}
Configuration Files
appsettings.json
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Ocelot": "Information"
}
}
}
ocelot.json
{
"Routes": [
{
"DownstreamPathTemplate": "/api/{everything}",
"DownstreamScheme": "http",
"DownstreamHostAndPorts": [
{
"Host": "localhost",
"Port": 5001
}
],
"UpstreamPathTemplate": "/users/{everything}",
"UpstreamHttpMethod": [ "Get", "Post", "Put", "Delete" ]
},
{
"DownstreamPathTemplate": "/api/{everything}",
"DownstreamScheme": "http",
"DownstreamHostAndPorts": [
{
"Host": "localhost",
"Port": 5002
}
],
"UpstreamPathTemplate": "/orders/{everything}",
"UpstreamHttpMethod": [ "Get", "Post", "Put", "Delete" ]
}
],
"GlobalConfiguration": {
"BaseUrl": "https://api.example.com"
}
}
ocelot.json with Consul
{
"Routes": [
{
"DownstreamPathTemplate": "/api/{everything}",
"DownstreamScheme": "http",
"ServiceName": "user-service",
"LoadBalancerOptions": {
"Type": "RoundRobin"
},
"UpstreamPathTemplate": "/users/{everything}",
"UpstreamHttpMethod": [ "Get", "Post", "Put", "Delete" ]
},
{
"DownstreamPathTemplate": "/api/{everything}",
"DownstreamScheme": "http",
"ServiceName": "order-service",
"LoadBalancerOptions": {
"Type": "LeastConnection"
},
"UpstreamPathTemplate": "/orders/{everything}",
"UpstreamHttpMethod": [ "Get", "Post", "Put", "Delete" ]
}
],
"GlobalConfiguration": {
"BaseUrl": "https://api.example.com",
"ServiceDiscoveryProvider": {
"Scheme": "http",
"Host": "consul",
"Port": 8500,
"Type": "Consul"
}
}
}
Key Components
GatewayHostBootstrapper
Singleton bootstrapper for API Gateway applications.
await GatewayHostBootstrapper.Instance.RunAsync<Startup>(args);
GatewayStartup
Abstract base class with Ocelot and Consul configuration.
public class MyGatewayStartup : GatewayStartup
{
protected override bool EnableForwardedHeaderOptions => true;
protected override bool ForceHttps => false;
protected override bool AddControllersWithViews => false;
}
Features in Detail
Request Routing
Route incoming requests to downstream services:
{
"DownstreamPathTemplate": "/api/v1/products/{id}",
"DownstreamScheme": "https",
"DownstreamHostAndPorts": [
{ "Host": "product-api.internal", "Port": 443 }
],
"UpstreamPathTemplate": "/products/{id}",
"UpstreamHttpMethod": [ "Get" ]
}
Service Discovery with Consul
Automatically discover service instances:
{
"ServiceName": "product-service",
"ServiceDiscoveryProvider": {
"Host": "consul.service.consul",
"Port": 8500,
"Type": "Consul"
}
}
Services register with Consul, and the gateway automatically discovers available instances.
Load Balancing
Distribute requests across multiple instances:
{
"LoadBalancerOptions": {
"Type": "RoundRobin"
}
}
Available Load Balancers:
LeastConnection- Route to instance with fewest connectionsRoundRobin- Distribute evenly across instancesNoLoadBalancer- Use first available instance
Rate Limiting
Control request rates per endpoint:
{
"RateLimitOptions": {
"ClientWhitelist": [],
"EnableRateLimiting": true,
"Period": "1s",
"PeriodTimespan": 1,
"Limit": 10
}
}
Caching
Cache downstream responses:
{
"FileCacheOptions": {
"TtlSeconds": 60,
"Region": "products"
}
}
Quality of Service
Configure circuit breakers and timeouts:
{
"QoSOptions": {
"ExceptionsAllowedBeforeBreaking": 3,
"DurationOfBreak": 1000,
"TimeoutValue": 5000
}
}
Authentication & Authorization
Forward or validate authentication:
{
"AuthenticationOptions": {
"AuthenticationProviderKey": "Bearer",
"AllowedScopes": []
}
}
Request/Response Transformation
Transform headers and body:
{
"UpstreamHeaderTransform": {
"X-Forwarded-For": "{RemoteIpAddress}"
},
"DownstreamHeaderTransform": {
"X-Custom-Header": "CustomValue"
}
}
Forwarded Headers
When behind a reverse proxy or load balancer:
protected override bool EnableForwardedHeaderOptions => true;
This configures:
X-Forwarded-For- Client IP addressX-Forwarded-Proto- Original protocol (http/https)X-Forwarded-Host- Original host header
All known networks and proxies are allowed (suitable for internal networks).
Advanced Configuration
Aggregation
Aggregate multiple downstream requests:
{
"Aggregates": [
{
"RouteKeys": [
"user-details",
"user-orders"
],
"UpstreamPathTemplate": "/users/{id}/profile"
}
]
}
Custom Middleware
Add custom middleware before Ocelot:
public override void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILoggerFactory logger)
{
// Add custom middleware before base.Configure
app.UseMiddleware<MyCustomMiddleware>();
base.Configure(app, env, logger);
}
Additional Services
Add services to the gateway:
public override void ConfigureServices(IServiceCollection services)
{
base.ConfigureServices(services);
services.AddScoped<IMyService, MyService>();
}
Typical Architecture
???????????
? Client ?
???????????
?
?
???????????????????
? API Gateway ? (Indiko.Hosting.Gateway)
? (Ocelot) ?
???????????????????
?
????????????????????
? ?
? ?
???????????????? ????????????????
? User Service ? ?Order Service ?
? (Consul) ? ? (Consul) ?
???????????????? ????????????????
Configuration Loading
Ocelot configuration is typically loaded from ocelot.json:
// In Program.cs or startup configuration
builder.Configuration.AddJsonFile("ocelot.json");
Environment-specific configurations:
ocelot.json
ocelot.Development.json
ocelot.Production.json
Target Framework
- .NET 10
Dependencies
Indiko.Hosting.AbstractionsIndiko.Blocks.Common.AbstractionsIndiko.Blocks.Common.ManagementOcelotOcelot.Provider.ConsulMicrosoft.AspNetCore.App
License
See LICENSE file in the repository root.
Related Packages
Indiko.Hosting.Abstractions- Core hosting abstractionsIndiko.Blocks.Communication.ServiceToService.Consul- Service-to-service communicationIndiko.Blocks.Tracing.OpenTelemetry- Distributed tracing for gatewayIndiko.Blocks.Logging.Serilog- Structured logging
Resources
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- Indiko.Hosting.Abstractions (>= 2.1.0)
- Microsoft.AspNetCore.Mvc.NewtonsoftJson (>= 10.0.0)
- Microsoft.Extensions.Configuration.Abstractions (>= 10.0.0)
- Microsoft.Extensions.DependencyModel (>= 10.0.0)
- Ocelot (>= 24.0.1)
- Ocelot.Provider.Consul (>= 24.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 2.1.1 | 26 | 12/2/2025 |
| 2.1.0 | 26 | 12/2/2025 |
| 2.0.0 | 265 | 9/17/2025 |
| 1.7.23 | 179 | 9/8/2025 |
| 1.7.22 | 176 | 9/8/2025 |
| 1.7.21 | 162 | 8/14/2025 |
| 1.7.20 | 164 | 6/23/2025 |
| 1.7.19 | 152 | 6/3/2025 |
| 1.7.18 | 158 | 5/29/2025 |
| 1.7.17 | 173 | 5/26/2025 |
| 1.7.15 | 128 | 4/12/2025 |
| 1.7.14 | 147 | 4/11/2025 |
| 1.7.13 | 133 | 3/29/2025 |
| 1.7.12 | 161 | 3/28/2025 |
| 1.7.11 | 156 | 3/28/2025 |
| 1.7.10 | 156 | 3/28/2025 |
| 1.7.9 | 155 | 3/28/2025 |
| 1.7.8 | 156 | 3/28/2025 |
| 1.7.5 | 181 | 3/17/2025 |
| 1.7.4 | 173 | 3/16/2025 |
| 1.7.3 | 166 | 3/16/2025 |
| 1.7.2 | 178 | 3/16/2025 |
| 1.7.1 | 205 | 3/11/2025 |
| 1.6.8 | 212 | 3/11/2025 |
| 1.6.7 | 246 | 3/4/2025 |
| 1.6.6 | 133 | 2/26/2025 |
| 1.6.5 | 141 | 2/20/2025 |
| 1.6.4 | 145 | 2/20/2025 |
| 1.6.3 | 138 | 2/5/2025 |
| 1.6.2 | 119 | 1/24/2025 |
| 1.6.1 | 127 | 1/24/2025 |
| 1.6.0 | 141 | 1/16/2025 |
| 1.5.2 | 146 | 1/16/2025 |
| 1.5.1 | 167 | 11/3/2024 |
| 1.5.0 | 158 | 10/26/2024 |
| 1.3.2 | 126 | 10/24/2024 |
| 1.3.0 | 149 | 10/10/2024 |
| 1.2.5 | 142 | 10/9/2024 |
| 1.2.4 | 143 | 10/8/2024 |
| 1.2.1 | 141 | 10/3/2024 |
| 1.2.0 | 142 | 9/29/2024 |
| 1.1.1 | 140 | 9/23/2024 |
| 1.1.0 | 179 | 9/18/2024 |
| 1.0.33 | 160 | 9/15/2024 |
| 1.0.28 | 159 | 8/28/2024 |
| 1.0.27 | 165 | 8/24/2024 |
| 1.0.26 | 180 | 7/7/2024 |
| 1.0.25 | 159 | 7/6/2024 |
| 1.0.24 | 143 | 6/25/2024 |
| 1.0.23 | 134 | 6/1/2024 |
| 1.0.22 | 153 | 5/14/2024 |
| 1.0.21 | 128 | 5/14/2024 |
| 1.0.20 | 166 | 4/8/2024 |
| 1.0.19 | 138 | 4/3/2024 |
| 1.0.18 | 167 | 3/23/2024 |
| 1.0.17 | 178 | 3/19/2024 |
| 1.0.16 | 172 | 3/19/2024 |
| 1.0.15 | 163 | 3/11/2024 |
| 1.0.14 | 168 | 3/10/2024 |
| 1.0.13 | 141 | 3/6/2024 |
| 1.0.12 | 164 | 3/1/2024 |
| 1.0.11 | 165 | 3/1/2024 |
| 1.0.10 | 178 | 3/1/2024 |
| 1.0.9 | 205 | 3/1/2024 |
| 1.0.8 | 178 | 2/19/2024 |
| 1.0.7 | 173 | 2/17/2024 |
| 1.0.6 | 163 | 2/17/2024 |
| 1.0.5 | 166 | 2/17/2024 |
| 1.0.4 | 171 | 2/7/2024 |
| 1.0.3 | 142 | 2/6/2024 |
| 1.0.1 | 144 | 2/6/2024 |
| 1.0.0 | 215 | 1/9/2024 |
| 1.0.0-preview99 | 176 | 12/22/2023 |
| 1.0.0-preview98 | 133 | 12/21/2023 |
| 1.0.0-preview97 | 146 | 12/21/2023 |
| 1.0.0-preview96 | 161 | 12/20/2023 |
| 1.0.0-preview94 | 126 | 12/18/2023 |
| 1.0.0-preview93 | 198 | 12/13/2023 |
| 1.0.0-preview92 | 149 | 12/13/2023 |
| 1.0.0-preview91 | 155 | 12/12/2023 |
| 1.0.0-preview90 | 164 | 12/11/2023 |
| 1.0.0-preview89 | 150 | 12/11/2023 |
| 1.0.0-preview88 | 171 | 12/6/2023 |
| 1.0.0-preview87 | 149 | 12/6/2023 |
| 1.0.0-preview86 | 156 | 12/6/2023 |
| 1.0.0-preview85 | 124 | 12/6/2023 |
| 1.0.0-preview84 | 157 | 12/5/2023 |
| 1.0.0-preview83 | 144 | 12/5/2023 |
| 1.0.0-preview82 | 154 | 12/5/2023 |
| 1.0.0-preview81 | 132 | 12/4/2023 |
| 1.0.0-preview80 | 130 | 12/1/2023 |
| 1.0.0-preview77 | 145 | 12/1/2023 |
| 1.0.0-preview76 | 145 | 12/1/2023 |
| 1.0.0-preview75 | 146 | 12/1/2023 |
| 1.0.0-preview74 | 132 | 11/26/2023 |
| 1.0.0-preview73 | 157 | 11/7/2023 |
| 1.0.0-preview72 | 138 | 11/6/2023 |
| 1.0.0-preview71 | 150 | 11/3/2023 |
| 1.0.0-preview70 | 151 | 11/2/2023 |
| 1.0.0-preview69 | 148 | 11/2/2023 |
| 1.0.0-preview68 | 148 | 11/2/2023 |
| 1.0.0-preview67 | 141 | 11/2/2023 |
| 1.0.0-preview66 | 130 | 11/2/2023 |
| 1.0.0-preview65 | 145 | 11/2/2023 |
| 1.0.0-preview64 | 144 | 11/2/2023 |
| 1.0.0-preview63 | 144 | 11/2/2023 |
| 1.0.0-preview62 | 152 | 11/1/2023 |
| 1.0.0-preview61 | 147 | 11/1/2023 |
| 1.0.0-preview60 | 134 | 11/1/2023 |
| 1.0.0-preview59 | 153 | 11/1/2023 |
| 1.0.0-preview58 | 121 | 10/31/2023 |
| 1.0.0-preview57 | 135 | 10/31/2023 |
| 1.0.0-preview56 | 136 | 10/31/2023 |
| 1.0.0-preview55 | 132 | 10/31/2023 |
| 1.0.0-preview54 | 148 | 10/31/2023 |
| 1.0.0-preview53 | 148 | 10/31/2023 |
| 1.0.0-preview52 | 137 | 10/31/2023 |
| 1.0.0-preview51 | 147 | 10/31/2023 |
| 1.0.0-preview50 | 133 | 10/31/2023 |
| 1.0.0-preview48 | 130 | 10/31/2023 |
| 1.0.0-preview46 | 143 | 10/31/2023 |
| 1.0.0-preview45 | 147 | 10/31/2023 |
| 1.0.0-preview44 | 148 | 10/31/2023 |
| 1.0.0-preview43 | 146 | 10/31/2023 |
| 1.0.0-preview42 | 141 | 10/30/2023 |
| 1.0.0-preview41 | 143 | 10/30/2023 |
| 1.0.0-preview40 | 154 | 10/27/2023 |
| 1.0.0-preview39 | 148 | 10/27/2023 |
| 1.0.0-preview38 | 147 | 10/27/2023 |
| 1.0.0-preview37 | 133 | 10/27/2023 |
| 1.0.0-preview36 | 125 | 10/27/2023 |
| 1.0.0-preview35 | 138 | 10/27/2023 |
| 1.0.0-preview34 | 148 | 10/27/2023 |
| 1.0.0-preview33 | 158 | 10/26/2023 |
| 1.0.0-preview32 | 141 | 10/26/2023 |
| 1.0.0-preview31 | 147 | 10/26/2023 |
| 1.0.0-preview30 | 164 | 10/26/2023 |
| 1.0.0-preview29 | 152 | 10/26/2023 |
| 1.0.0-preview28 | 134 | 10/26/2023 |
| 1.0.0-preview27 | 147 | 10/26/2023 |
| 1.0.0-preview26 | 146 | 10/25/2023 |
| 1.0.0-preview25 | 146 | 10/23/2023 |
| 1.0.0-preview24 | 157 | 10/23/2023 |
| 1.0.0-preview23 | 152 | 10/23/2023 |
| 1.0.0-preview22 | 154 | 10/23/2023 |
| 1.0.0-preview21 | 130 | 10/23/2023 |
| 1.0.0-preview20 | 165 | 10/20/2023 |
| 1.0.0-preview19 | 139 | 10/19/2023 |
| 1.0.0-preview18 | 160 | 10/18/2023 |
| 1.0.0-preview16 | 132 | 10/11/2023 |
| 1.0.0-preview101 | 149 | 1/5/2024 |