A flexible and scalable API Gateway built with Spring Cloud Gateway, supporting dynamic route management, advanced traffic control, and real-time monitoring.
A flexible and scalable API Gateway built with Spring Cloud Gateway, supporting dynamic route management, advanced traffic control, and real-time monitoring.
- Dynamic Route Management: Create, update, delete and query routes via REST API
- MongoDB Storage: Route definitions persisted in MongoDB
- Circuit Breaker: Prevent cascading failures with configurable circuit breakers
- Rate Limiting: Control request rates to protect backend services
- Timeout Handling: Configure timeouts for backend service requests
- Path Rewriting: Rewrite request paths before forwarding to backend services
- Metrics Collection: Track request metrics in MongoDB
- Prometheus Integration: Expose metrics for Prometheus scraping
- Grafana Dashboard: Visualize API Gateway metrics in real-time
- Request Logging: Comprehensive logging of request/response details
- Authentication & Authorization: OAuth2/JWT support
- API Key Management: Issue and validate API keys
- Request Validation: Validate incoming requests against schemas
- Response Transformation: Modify service responses
- Service Discovery: Integrate with service registry (Eureka/Consul)
- Caching: Response caching for improved performance
- Custom Filters: Plugin architecture for custom request/response filters
- Advanced Analytics: Detailed traffic analysis and reporting
- Multi-tenancy: Support for tenant isolation
- API Documentation: Auto-generated API documentation
- Spring Boot/Cloud Gateway: Core API Gateway functionality
- Spring WebFlux: Reactive programming model
- MongoDB: Route and metrics storage
- Redis: Rate limiting and distributed state
- Prometheus: Metrics collection
- Grafana: Metrics visualization
- Docker: Containerization
- Docker Compose: Multi-container orchestration
- Java 17+
- Maven 3.8+
- Docker & Docker Compose
- MongoDB (or use the Docker Compose setup)
-
Clone the repository:
git clone https://github.com/yourusername/api_gateway.git cd api_gateway
-
Build the project:
cd api_gateway mvn clean package
-
Start the API Gateway:
mvn spring-boot:run
-
The API Gateway will be available at http://localhost:8080
-
Start the monitoring dashboard:
cd dashboard docker-compose up -d
-
Access Grafana at http://localhost:3000 (default credentials: admin/admin)
-
Create a route:
curl -X POST http://localhost:8080/api/routes \ -H "Content-Type: application/json" \ -d '{ "routeId": "example-route", "path": "/example/**", "method": "GET", "uri": "http://example-service:8080", "enabled": true }'
-
Get all routes:
curl -X GET http://localhost:8080/api/routes
-
Get a specific route:
curl -X GET http://localhost:8080/api/routes/{routeId}
-
Update a route:
curl -X PUT http://localhost:8080/api/routes/{routeId} \ -H "Content-Type: application/json" \ -d '{ "path": "/updated-path/**", "enabled": true }'
-
Delete a route:
curl -X DELETE http://localhost:8080/api/routes/{routeId}
-
Refresh routes:
curl -X POST http://localhost:8080/api/routes/refresh
-
Circuit Breaker:
curl -X POST http://localhost:8080/api/routes \ -H "Content-Type: application/json" \ -d '{ "routeId": "circuit-test", "path": "/circuit/**", "method": "GET", "uri": "http://service:8080", "enabled": true, "circuitBreaker": { "name": "circuitTest", "failureRateThreshold": 50, "slidingWindowSize": 10, "waitDurationInOpenState": "PT5S", "permittedCallsInHalfOpenState": 2, "automaticTransition": true, "fallbackUri": "forward:/local-test" } }'
-
Rate Limiter:
curl -X POST http://localhost:8080/api/routes \ -H "Content-Type: application/json" \ -d '{ "routeId": "rate-limited", "path": "/limited/**", "method": "GET", "uri": "http://service:8080", "enabled": true, "rateLimiter": { "replenishRate": 1, "burstCapacity": 2, "requestedTokens": 1 } }'
This project is licensed under the MIT License - see the LICENSE file for details.