API Gateway
The API Gateway provides enterprise-grade traffic management for your APIs.
Creating a Gateway
Via Web UI
- Navigate to Gateways in the sidebar
- Click Create Gateway
- Enter:
- Name: Descriptive name for your gateway
- Subdomain: URL prefix (e.g.,
myapi→myapi.gateway.tunnelapi.in) - Description: Optional description
Via API
curl -X POST https://api.tunnelapi.in/api/gateways \
-H "Authorization: Bearer YOUR_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"name": "My API Gateway",
"subdomain": "myapi",
"description": "Production API gateway"
}'
Managing Routes
Routes define how incoming requests are matched and forwarded to backends.
{
"name": "API Route",
"path": "/api/v1",
"pathType": "prefix", // prefix, exact, regex
"methods": ["GET", "POST"],
"backends": [
{
"url": "http://backend1:3000",
"weight": 70,
"healthCheck": {
"enabled": true,
"path": "/health",
"interval": 30000
}
},
{
"url": "http://backend2:3000",
"weight": 30
}
],
"loadBalancing": {
"strategy": "weighted"
}
}
Path Types
| Type | Behavior | Example |
|---|---|---|
prefix | Matches path prefix | /api matches /api, /api/users |
exact | Exact path match | /api matches only /api |
regex | Regular expression | /api/v[0-9]+ |
Rate Limiting
Configure rate limits per gateway or per route:
{
"rateLimit": {
"enabled": true,
"requestsPerSecond": 100,
"burstSize": 150
}
}
Request Transformation
Transform requests before forwarding:
{
"transformations": {
"addHeaders": {
"X-Gateway-ID": "{{gateway.id}}",
"X-Request-ID": "{{uuid}}"
},
"removeHeaders": ["X-Internal-Header"],
"modifyHeaders": {
"Host": "internal-service.local"
}
}
}
Analytics
Monitor your gateway traffic:
- Request Count - Total requests processed
- Bytes In/Out - Bandwidth usage
- Error Count - Failed requests
- Average Latency - Response time