跳转到内容

Routes

此内容尚不支持你的语言。

Routes define how incoming requests are matched and routed to backend services.

interface Route {
id: string;
name: string;
serviceId?: string;
protocols?: string[]; // ["http", "https"]
methods?: string[]; // ["GET", "POST", ...]
hosts?: string[]; // ["api.example.com"]
paths?: string[]; // ["/api/v1/*"]
headers?: Record<string, string | string[]>;
stripPath?: boolean;
preserveHost?: boolean;
tags?: string[];
}

Remove matched prefix before forwarding:

{
"paths": ["/api/v1/*"],
"stripPath": true
}

Request: /api/v1/users → Backend receives: /users

Keep original host header when forwarding:

{
"preserveHost": true
}

Default: gateway replaces host with backend target host.

Routes are matched by specificity:

  1. Exact paths before wildcards
  2. More specific wildcards before broader ones
  3. Regex priority can override order
{
"regexPriority": 100 // Higher priority wins
}
Terminal window
curl http://localhost:8080/api/routes
Terminal window
curl http://localhost:8080/api/routes?serviceId=service_abc123
Terminal window
curl -X PATCH http://localhost:8080/api/routes/route_xyz789 \
-H "Content-Type: application/json" \
-d '{
"methods": ["GET", "POST", "PUT", "DELETE"]
}'
Terminal window
curl -X DELETE http://localhost:8080/api/routes/route_xyz789

Bind plugins to specific routes:

Terminal window
curl -X POST http://localhost:8080/api/plugins \
-H "Content-Type: application/json" \
-d '{
"routeId": "route_xyz789",
"pluginName": "key-auth",
"config": {
"required": true
}
}'

Route based on domain:

{
"hosts": ["api.example.com", "internal.example.com"]
}

Different domains can route to different services.

Limit to specific protocols:

{
"protocols": ["https"] // Only HTTPS requests
}