API Gateway Configuration
Centralize API gateway configuration for microservices with service-specific rate limiting, authentication strategies, and CORS policies.
The Problem
Section titled “The Problem”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
The JSSON Solution
Section titled “The JSSON Solution”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"]{"routes": [ { "id": "auth-v2", "service": "auth", "path": "/api/v2/auth", "authType": "jwt", "tokenExpiry": 7200, "requestsPerMinute": 100, "burstSize": 100, "allowMethods": ["GET", "POST", "PUT", "DELETE"], "allowHeaders": ["Content-Type", "Authorization"], "cacheEnabled": false, "cacheTTL": 300 } // ... more routes]}Key Features
Section titled “Key Features”Arrays in Objects
Section titled “Arrays in Objects”allowMethods = ["GET", "POST", "PUT", "DELETE"]allowHeaders = ["Content-Type", "Authorization"]Nested Ternary Logic
Section titled “Nested Ternary Logic”requestsPerMinute = route.service == "auth" ? 100 : (route.service == "payment" ? 50 : 1000)Different rate limits per service type!
When to Use
Section titled “When to Use”✅ Perfect for:
- API gateway configurations
- Microservices routing
- Rate limiting policies
- CORS management
Try It!
Section titled “Try It!”- Save to
api-gateway.jsson - Run:
jsson -i api-gateway.jsson - Configure your gateway!
What’s Next?
Section titled “What’s Next?”- Feature Flags — Environment configs
- i18n — Multi-language support
Centralize your API config! 🌐