Indiko.Hosting.Gateway 2.1.4

dotnet add package Indiko.Hosting.Gateway --version 2.1.4
                    
NuGet\Install-Package Indiko.Hosting.Gateway -Version 2.1.4
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Indiko.Hosting.Gateway" Version="2.1.4" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Indiko.Hosting.Gateway" Version="2.1.4" />
                    
Directory.Packages.props
<PackageReference Include="Indiko.Hosting.Gateway" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Indiko.Hosting.Gateway --version 2.1.4
                    
#r "nuget: Indiko.Hosting.Gateway, 2.1.4"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Indiko.Hosting.Gateway@2.1.4
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Indiko.Hosting.Gateway&version=2.1.4
                    
Install as a Cake Addin
#tool nuget:?package=Indiko.Hosting.Gateway&version=2.1.4
                    
Install as a Cake Tool

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 connections
  • RoundRobin - Distribute evenly across instances
  • NoLoadBalancer - 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 address
  • X-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.Abstractions
  • Indiko.Blocks.Common.Abstractions
  • Indiko.Blocks.Common.Management
  • Ocelot
  • Ocelot.Provider.Consul
  • Microsoft.AspNetCore.App

License

See LICENSE file in the repository root.

  • Indiko.Hosting.Abstractions - Core hosting abstractions
  • Indiko.Blocks.Communication.ServiceToService.Consul - Service-to-service communication
  • Indiko.Blocks.Tracing.OpenTelemetry - Distributed tracing for gateway
  • Indiko.Blocks.Logging.Serilog - Structured logging

Resources

Product 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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.4 82 3/2/2026
2.1.3 87 2/27/2026
2.1.2 283 12/18/2025
2.1.1 682 12/2/2025
2.1.0 680 12/2/2025
2.0.0 287 9/17/2025
1.7.23 208 9/8/2025
1.7.22 201 9/8/2025
1.7.21 191 8/14/2025
1.7.20 185 6/23/2025
1.7.19 184 6/3/2025
1.7.18 190 5/29/2025
1.7.17 206 5/26/2025
1.7.15 151 4/12/2025
1.7.14 172 4/11/2025
1.7.13 163 3/29/2025
1.7.12 189 3/28/2025
1.7.11 185 3/28/2025
1.7.10 179 3/28/2025
1.7.9 178 3/28/2025
Loading failed