OxiGDAL Gateway
Enterprise-grade API gateway for geospatial services with comprehensive features including rate limiting, authentication, GraphQL support, and WebSocket handling. Built in pure Rust for high performance and reliability.
Features
- Rate Limiting: Multiple algorithms (token bucket, leaky bucket, fixed/sliding window) with memory and distributed Redis backends
- Authentication: API keys, JWT tokens, OAuth2/OIDC integration, session management, and multi-factor authentication (MFA)
- API Versioning: Support for multiple API versions with content negotiation, migration, and deprecation handling
- GraphQL Support: Full GraphQL server with queries, mutations, subscriptions, and schema management
- WebSocket: Real-time bidirectional communication with connection multiplexing and message routing
- Middleware Stack: CORS, response compression (gzip/brotli), response caching, structured logging, and metrics collection
- Load Balancing: Multiple strategies (round-robin, least connections, weighted) with health checks and circuit breaker patterns
- Request/Response Transformation: Format adaptation and data transformation pipelines
- Authorization: Role-based access control (RBAC) with fine-grained permission management
- Pure Rust: 100% Pure Rust implementation with zero C/Fortran dependencies
- Error Handling: Comprehensive error types with proper HTTP status codes and retry semantics
Installation
Add to your Cargo.toml:
[]
= "0.1"
= { = "1", = ["full"] }
Feature Flags
# In-memory rate limiting (default)
= { = "0.1", = ["memory"] }
# Distributed rate limiting with Redis
= { = "0.1", = ["redis"] }
Quick Start
Basic Gateway Setup
use ;
async
With Custom Configuration
use ;
use AuthConfig;
use RateLimitConfig;
async
Usage
Authentication
API Key Authentication
use ApiKeyAuthenticator;
async
JWT Authentication
use ;
async
OAuth2 Integration
use ;
async
Rate Limiting
Token Bucket Algorithm
use ;
async
Distributed Rate Limiting with Redis
use ;
async
GraphQL
use ;
async
WebSocket Support
use ;
async
Middleware
use ;
let mut middleware_config = default;
// Enable CORS
middleware_config.enable_cors = true;
middleware_config.allowed_origins = vec!;
// Configure compression
middleware_config.enable_compression = true;
middleware_config.compression_level = Best;
// Enable caching
middleware_config.enable_caching = true;
middleware_config.cache_ttl = 300; // 5 minutes
// Enable metrics
middleware_config.enable_metrics = true;
middleware_config.enable_logging = true;
Load Balancing
use ;
async
API Versioning
use ;
let negotiator = new;
// Automatically handles version negotiation from headers or URL path
// Supports deprecation warnings and migration paths
API Overview
Core Modules
| Module | Description |
|---|---|
auth |
Authentication and authorization (API keys, JWT, OAuth2, sessions, MFA, RBAC) |
rate_limit |
Rate limiting with multiple algorithms and storage backends |
graphql |
GraphQL server with queries, mutations, subscriptions, and schema management |
websocket |
WebSocket support with multiplexing and message routing |
middleware |
HTTP middleware stack (CORS, compression, caching, logging, metrics) |
loadbalancer |
Load balancing with health checks and circuit breaker |
transform |
Request/response transformation and format adaptation |
versioning |
API versioning, negotiation, migration, and deprecation |
error |
Comprehensive error types and handling |
Authentication Submodules
| Module | Description |
|---|---|
auth::api_key |
API key generation and validation |
auth::jwt |
JWT token creation and verification |
auth::oauth2 |
OAuth2/OIDC provider integration |
auth::session |
Session management and tracking |
auth::mfa |
Multi-factor authentication support |
auth::permissions |
Fine-grained permission management |
auth::rbac |
Role-based access control |
Rate Limiting Submodules
| Module | Description |
|---|---|
rate_limit::algorithms |
Token bucket, leaky bucket, fixed/sliding window |
rate_limit::rules |
Rule engine for complex rate limiting policies |
rate_limit::storage |
In-memory and Redis storage backends |
Configuration
GatewayConfig
Error Handling
This library follows the "no unwrap" policy. All fallible operations return Result<T, E> with descriptive error types:
use ;
// GatewayError variants include:
// - RateLimitExceeded { message, retry_after }
// - AuthenticationFailed(String)
// - AuthorizationFailed(String)
// - InvalidApiKey
// - TokenExpired
// - InvalidToken(String)
// - GraphQLError(String)
// - WebSocketError(String)
// - UnsupportedVersion { version, supported }
// - BackendUnavailable(String)
// - CircuitBreakerOpen(String)
// - Timeout(String)
// ... and more
// Errors provide HTTP status codes and retry information
let error = RateLimitExceeded ;
let status = error.status_code; // HTTP 429
let retryable = error.is_retryable; // true
let retry_after = error.retry_after; // Some(60)
Performance
The gateway is designed for high-performance, enterprise-scale deployments:
- Asynchronous: Built on Tokio for non-blocking I/O
- Efficient Rate Limiting: In-memory rate limiting with O(1) operations
- Distributed Support: Optional Redis backend for distributed deployments
- Connection Pooling: Manages backend connections efficiently
- Compression: Automatic response compression (gzip/brotli)
- Caching: Built-in response caching to reduce backend load
Benchmarks
Run performance benchmarks with:
Benchmark measurements on typical hardware:
| Operation | Time |
|---|---|
| Rate limit check | <1µs |
| API key validation | <10µs |
| JWT verification | <100µs |
| Request routing | <50µs |
Examples
See the tests directory for integration examples:
auth_test.rs- Authentication and authorization examplesgraphql_test.rs- GraphQL server integrationmiddleware_test.rs- Middleware stack usagewebsocket_test.rs- WebSocket real-time communication
Documentation
Full documentation is available at docs.rs.
View locally with:
Testing
Run the test suite:
# All tests
# With specific features
# Integration tests
Pure Rust
This library is 100% Pure Rust with no C/Fortran dependencies. All functionality works out of the box without external libraries or system dependencies.
OxiGDAL Ecosystem
This project is part of the OxiGDAL ecosystem for geospatial data processing:
- OxiGDAL-Core: Core geospatial data structures and operations
- OxiGDAL-Algorithms: Geospatial algorithms and transformations
- OxiGDAL-Drivers: File format readers/writers (GeoTIFF, GeoJSON, Shapefile, etc.)
- OxiGDAL-Server: HTTP server for geospatial services
- OxiGDAL-Cloud: Cloud deployment support
Contributing
Contributions are welcome! This project follows:
- No Unwrap Policy: All fallible operations must use
Resulttypes - No Warnings: Code must compile without warnings
- Pure Rust: No C/Fortran dependencies in default features
- File Size: Source files should be kept under 2000 lines
See contributing guidelines for more information.
License
Licensed under the Apache License, Version 2.0.
Related Projects
- OxiGDAL-Core - Core geospatial library
- OxiGDAL-Server - HTTP server
- OxiGDAL-CLI - Command-line tools
Part of the COOLJAPAN ecosystem of pure Rust geospatial libraries and tools.