Skip to content

API Gateway Configuration

Centralize API gateway configuration for microservices with service-specific rate limiting, authentication strategies, and CORS policies.

API gateways require dozens of similar route definitions with slight variations:

  • Repetitive configs — Copy-pasting route definitions
  • Inconsistent settings — Easy to miss rate limits or auth rules
  • Hard to maintain — Adding a service requires updating multiple places
routes [
template { service, version, basePath }
map (route) = {
id = route.service + "-v" + route.version
service = route.service
path = "/api/v" + route.version + "/" + route.basePath
// Auth based on version
authType = route.version >= 2 ? "jwt" : "basic"
tokenExpiry = route.version >= 3 ? 3600 : 7200
// Rate limiting based on service
requestsPerMinute = route.service == "auth" ? 100 : (route.service == "payment" ? 50 : 1000)
burstSize = route.service == "payment" ? 10 : 100
// CORS
allowMethods = ["GET", "POST", "PUT", "DELETE"]
allowHeaders = ["Content-Type", "Authorization"]
// Caching
cacheEnabled = route.service == "catalog" ? true : false
cacheTTL = 300
}
"auth", 2, "auth"
"payment", 2, "payments"
"catalog", 3, "products"
"users", 2, "users"
]
allowMethods = ["GET", "POST", "PUT", "DELETE"]
allowHeaders = ["Content-Type", "Authorization"]
requestsPerMinute = route.service == "auth" ? 100 : (route.service == "payment" ? 50 : 1000)

Different rate limits per service type!

Perfect for:

  • API gateway configurations
  • Microservices routing
  • Rate limiting policies
  • CORS management
  1. Save to api-gateway.jsson
  2. Run: jsson -i api-gateway.jsson
  3. Configure your gateway!

Centralize your API config! 🌐