| Crates.io | revoke-gateway |
| lib.rs | revoke-gateway |
| version | 0.3.0 |
| created_at | 2025-07-13 06:21:05.885801+00 |
| updated_at | 2025-07-13 06:21:05.885801+00 |
| description | High-performance API gateway built on Cloudflare Pingora for Revoke framework |
| homepage | |
| repository | https://github.com/revoke/revoke |
| max_upload_size | |
| id | 1750035 |
| size | 90,360 |
High-performance API gateway built on Cloudflare Pingora for the Revoke microservices framework.
revoke-gateway is a production-ready API gateway that provides intelligent routing, load balancing, and resilience features for microservices. Built on top of Cloudflare's Pingora framework, it offers exceptional performance and reliability.
use revoke_gateway::{RevokeGateway, GatewayConfig};
use revoke_registry::memory::MemoryRegistry;
use revoke_core::{ServiceRegistry, ServiceInfo, Protocol};
use std::sync::Arc;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Create service registry
let registry = Arc::new(MemoryRegistry::new());
// Register a service
let service = ServiceInfo {
id: uuid::Uuid::new_v4(),
name: "user-service".to_string(),
version: "1.0.0".to_string(),
address: "127.0.0.1".to_string(),
port: 3000,
protocol: Protocol::Http,
metadata: Default::default(),
};
registry.register(service).await?;
// Configure gateway
let config = GatewayConfig {
bind: "0.0.0.0:8080".to_string(),
workers: 4,
log_level: "info".to_string(),
enable_health_check: true,
health_check_interval: 10,
backend_refresh_interval: 30,
};
// Create and start gateway
let gateway = RevokeGateway::new(registry)?;
gateway.run(config)?;
Ok(())
}
The gateway is configured using the GatewayConfig struct:
let config = GatewayConfig {
bind: "0.0.0.0:8080".to_string(), // Bind address
workers: 4, // Number of worker threads
log_level: "info".to_string(), // Log level
enable_health_check: true, // Enable health checks
health_check_interval: 10, // Health check interval in seconds
backend_refresh_interval: 30, // Backend refresh interval in seconds
};
Or via command line arguments:
revoke-gateway --bind 0.0.0.0:8080 --workers 4 --enable-health-check
/users/123 → users)The gateway automatically discovers services from the registry:
// Services register themselves with the registry
let service = ServiceInfo {
id: Uuid::new_v4(),
name: "user-service".to_string(),
address: "127.0.0.1".to_string(),
port: 3000,
protocol: Protocol::Http,
// ...
};
registry.register(service).await?;
// Gateway discovers services by name from URL path
// Request to /users/123 → looks up "users" service
The gateway uses Pingora's built-in load balancing:
// Gateway automatically creates load balancers for each service
// with Pingora's round-robin selection algorithm
// When a request comes in:
// 1. Extract service name from path
// 2. Get or create LoadBalancer for that service
// 3. Select a backend using round-robin
// 4. Proxy request to selected backend
The gateway caches load balancers per service for performance.
When enabled, the gateway uses Pingora's TCP health checks:
let config = GatewayConfig {
enable_health_check: true,
health_check_interval: 10, // seconds
// ...
};
Register multiple instances for load balancing:
// Register 3 instances of user-service
for i in 0..3 {
let service = ServiceInfo {
id: Uuid::new_v4(),
name: "user-service".to_string(),
address: "127.0.0.1".to_string(),
port: 3000 + i,
protocol: Protocol::Http,
metadata: Default::default(),
};
registry.register(service).await?;
}
// Gateway will automatically load balance requests across all instances
The gateway includes a basic router for custom routing logic:
use revoke_gateway::router::{Router, Route};
let mut router = Router::new();
router.add_route(Route {
path_prefix: "/api/v1".to_string(),
service_name: "api-service".to_string(),
strip_prefix: true,
});
// Match routes
if let Some(route) = router.match_route("/api/v1/users") {
println!("Matched service: {}", route.service_name);
}
// Memory registry (for testing)
use revoke_registry::memory::MemoryRegistry;
let registry = Arc::new(MemoryRegistry::new());
// Consul registry
use revoke_registry::consul::ConsulRegistry;
let registry = Arc::new(
ConsulRegistry::new(ConsulConfig::builder()
.address("http://localhost:8500")
.build()?)
.await?
);
Enable debug logging:
env_logger::init_from_env(
env_logger::Env::new().default_filter_or("revoke_gateway=debug")
);
See the examples directory for complete examples:
simple_gateway.rs - Basic gateway with single servicepingora_load_balancing.rs - Multiple service instances with load balancing