Overview
The Silky Gateway is a dedicated host that receives external HTTP requests and routes them to internal microservices via RPC. It handles cross-cutting concerns such as authentication, CORS, rate limiting, and Swagger aggregation.
Installation
<PackageReference Include="Silky.Http.Core" Version="3.9.2" />
<PackageReference Include="Silky.Http.Swagger" Version="3.9.2" />
<PackageReference Include="Silky.Http.CorsAccessor" Version="3.9.2" />
Basic Setup
Module
[DependsOn(
typeof(GatewayHostModule),
typeof(ZookeeperModule),
typeof(JwtModule),
typeof(CorsAccessorModule)
)]
public class GatewayModule : SilkyModule { }
Program.cs
await Host.CreateDefaultBuilder(args)
.ConfigureSilkyGatewayDefaults<GatewayModule>(webBuilder =>
{
webBuilder.UseStartup<Startup>();
})
.Build()
.RunAsync();
Startup.cs
public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
services
.AddSilkyHttpCore()
.AddSwaggerDocuments()
.AddCorsAccessor();
services.AddAuthentication("Bearer")
.AddJwtBearer(options => { /* ... */ });
}
public void Configure(IApplicationBuilder app)
{
app.UseCorsAccessor();
app.UseAuthentication();
app.UseAuthorization();
app.UseSwagger();
app.UseSwaggerUI(c =>
{
c.SwaggerEndpoint("/swagger/v1/swagger.json", "Silky Gateway V1");
});
app.UseSilkyRpcProxy(); // routes HTTP to internal RPC
app.UseEndpoints(endpoints =>
{
endpoints.MapSilkyRpcProxy();
});
}
}
Route Resolution
The gateway resolves the target RPC service entry from the incoming HTTP request path. Resolution follows the same rule as service entry WebAPI generation:
| Pattern | Maps To |
|---|---|
GET /api/order/{id} | IOrderAppService.GetAsync(id) |
POST /api/order | IOrderAppService.CreateOrderAsync(input) |
DELETE /api/order/{id} | IOrderAppService.DeleteAsync(id) |
Authentication
JWT authentication happens at the gateway. If a service entry is annotated with [Authorize], the gateway validates the Bearer token before forwarding the RPC call. Authenticated user claims are propagated to downstream services via RpcContext.
{
"jwt": {
"secret": "your-signing-key-here",
"issuer": "silky-gateway",
"audience": "silky-services",
"expiresIn": 7200
}
}
Swagger Aggregation
The gateway aggregates Swagger documents from all registered services and exposes a single Swagger UI:
{
"swagger": {
"enabled": true,
"title": "My Application Gateway",
"version": "v1",
"description": "API Gateway powered by Silky"
}
}
Custom WebAPI Route
Override the generated route on individual service entries:
[ServiceRoute]
public interface IOrderAppService
{
[HttpGet("/order/{id}")] // custom route — overrides auto-generated
Task<OrderOutput> GetAsync(long id);
}
Load Balancing
Gateway-to-service calls use the same load balancing as service-to-service calls. Configure the strategy:
{
"governanceOptions": {
"loadBalancer": "Polling"
}
}
Rate Limiting
Use the Silky.Http.RateLimit package to limit requests at the gateway level:
<PackageReference Include="Silky.Http.RateLimit" Version="3.9.2" />
See Service Governance for rate limit configuration.
