Skip to main content

Aggregation

Aggregation allows you to combine responses from multiple downstream services into a single response, reducing the number of requests clients need to make.

Configuration

Define aggregates in ocelot.json:

{
"Aggregates": [
{
"UpstreamPathTemplate": "/api/dashboard",
"RouteKeys": ["users", "orders"],
"UpstreamHost": ""
}
]
}

Each entry in RouteKeys must match the Key field of an existing route:

{
"Routes": [
{
"Key": "users",
"UpstreamPathTemplate": "/api/users",
"DownstreamPathTemplate": "/api/users",
"DownstreamScheme": "http",
"DownstreamHostAndPorts": [{ "Host": "users-service", "Port": 3000 }]
},
{
"Key": "orders",
"UpstreamPathTemplate": "/api/orders",
"DownstreamPathTemplate": "/api/orders",
"DownstreamScheme": "http",
"DownstreamHostAndPorts": [{ "Host": "orders-service", "Port": 3001 }]
}
]
}

Response Format

When a client calls GET /api/dashboard, the gateway calls both downstream services in parallel and returns:

{
"users": { ... },
"orders": { ... }
}

Each key in the response corresponds to a RouteKey.

Managing via Admin Panel

The admin panel provides a dedicated section for managing aggregations with a visual editor.