Expand description
§Web Server Abstraction - Production-Ready Framework
A comprehensive, production-ready web server abstraction layer providing a unified interface across multiple Rust web frameworks with enterprise-grade features.
§Key Features
- Framework Agnostic: Unified API for Axum, Actix-Web, Warp, Rocket, Salvo, Poem
- Ultra-Low Latency: Optimized for sub-millisecond response times
- Production Security: CSRF, XSS protection, input sanitization, TLS/SSL
- Unified Configuration: Centralized configuration with multiple sources (file, env, remote)
- Comprehensive Monitoring: Metrics, distributed tracing, health checks, alerting
- Multi-Language Support: FFI layer for Python, Node.js, Go, and C integration
- Performance Benchmarking: Built-in latency and throughput validation
- Enhanced Middleware: CORS, compression, rate limiting, security headers
- Type Safety: Leverages Rust’s type system for compile-time guarantees
- Async First: Built for modern async Rust with Tower ecosystem integration
§Supported Frameworks
- Axum - High-performance async web framework
- Actix-Web - Actor-based web framework
- Warp - Composable web framework
- Rocket - Type-safe web framework
- Salvo - Simple and powerful web framework
- Poem - Fast and powerful web framework
- Mock - For testing and development
§Quick Start
use web_server_abstraction::{WebServer, HttpMethod, Response};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let server = WebServer::new()
.route("/hello", HttpMethod::GET, |_req| async {
Ok(Response::ok().body("Hello, Production World!"))
})
.route("/health", HttpMethod::GET, |_req| async {
Ok(Response::ok()
.header("content-type", "application/json")
.body(r#"{"status": "healthy"}"#))
})
.bind("127.0.0.1:3000")
.await?;
server.run().await?;
Ok(())
}§Production Configuration
# config/server.yaml
server:
host: "0.0.0.0"
port: 8080
workers: 4
security:
csrf_protection: true
tls:
enabled: true
cert_path: "/path/to/cert.pem"
key_path: "/path/to/key.pem"
monitoring:
metrics_enabled: true
tracing_enabled: true
health_checks_enabled: trueRe-exports§
pub use auth::AuthContext;pub use auth::AuthContextConfig;pub use auth::AuthError;pub use auth::AuthMiddlewareResult;pub use auth::AuthRequirements;pub use auth::RequestAuthExt;pub use auth::UserSession;pub use auth::auth_middleware;pub use auth::enhanced_auth_middleware;pub use config::ConfigManager;pub use config::MonitoringConfig;pub use config::SecurityConfig;pub use config::WebServerConfig;pub use core::Handler;pub use core::HandlerFn;pub use core::Route;pub use core::WebServer;pub use enhanced_middleware::CompressionMiddleware;pub use enhanced_middleware::CorsMiddleware;pub use enhanced_middleware::EnhancedMiddleware;pub use enhanced_middleware::MiddlewareStack;pub use enhanced_middleware::RateLimitMiddleware;pub use enhanced_middleware::SecurityHeadersMiddleware;pub use error::Result;pub use error::WebServerError;pub use ffi::FfiContext;pub use ffi::ws_create_server as ffi_create_server;pub use monitoring::Alert;pub use monitoring::AlertSeverity;pub use monitoring::HealthStatus;pub use monitoring::MonitoringSystem;pub use monitoring::PerformanceStats;pub use monitoring::TraceContext;pub use performance::AdapterBenchmark;pub use performance::BenchmarkConfig;pub use performance::BenchmarkResults;pub use performance::LatencyCollector;pub use performance::PerformanceMetrics;pub use security::SecurityStats;pub use security::CspMiddleware;pub use security::CsrfMiddleware;pub use security::SecurityContext;pub use security::SecurityIssue;pub use security::SecurityMiddleware;pub use security::SecurityValidationResult;pub use security::XssProtectionMiddleware;pub use security::sanitize;pub use types::Cookie;pub use types::FileUpload;pub use types::Headers;pub use types::HttpMethod;pub use types::MultipartForm;pub use types::Request;pub use types::Response;pub use types::StatusCode;pub use content::CompressionMiddleware as LegacyCompressionMiddleware;pub use content::ContentNegotiationMiddleware;pub use database::ConnectionPool;pub use database::DatabaseConfig;pub use database::DatabaseConnection;pub use database::DatabaseError;pub use database::DatabaseValue;pub use database::FromDatabaseValue;pub use database::MockDatabase;pub use database::PoolStats;pub use database::QueryBuilder;pub use database::Row;pub use database::Transaction;pub use mountable::InterfaceBuilder;pub use mountable::InterfaceRegistry;pub use mountable::MountOptions;pub use mountable::MountableInterface;pub use mountable::OpenApiSpec;pub use mountable::RouteDefinition;pub use mountable::RouteDoc;pub use routing::Route as RoutePattern;pub use routing::Router;pub use session::MemorySessionStore;pub use session::Session;pub use session::SessionExt;pub use session::SessionManager;pub use session::SessionStore;pub use state::AppState;pub use state::Config;pub use state::Environment;pub use static_files::StaticFileConfig;pub use static_files::StaticFileHandler;pub use static_files::serve_static;pub use static_files::serve_static_with_prefix;pub use static_files::static_files;pub use benchmarks::BenchmarkConfig as LegacyBenchmarkConfig;pub use benchmarks::BenchmarkResults as LegacyBenchmarkResults;pub use benchmarks::PerformanceProfiler;pub use adapters::mock::MockAdapter;pub use adapters::axum::AxumAdapter;
Modules§
- adapters
- Framework adapters for different web frameworks.
- auth
- Comprehensive authentication and authorization integration.
- benchmarks
- Performance benchmarking and optimization tools.
- config
- Unified Configuration System
- content
- Content negotiation and advanced content handling.
- core
- Core traits and types for the web server abstraction.
- cross_
platform_ testing - Cross-Platform Testing Framework
- database
- Database integration helpers.
- enhanced_
middleware - Enhanced Middleware Integration
- error
- Error types for the web server abstraction.
- ffi
- FFI Layer - Multi-language SDK Support
- middleware
- Expanded middleware implementations with advanced features.
- monitoring
- Production Monitoring and Logging System
- mountable
- Mountable This module allows libraries to define web interfaces that can be mounted into any host application regardless of the underlying web framework. Now with deep authentication integration for seamless auth across all interfaces.
- performance
- Performance Benchmarking System
- routing
- security
- Production-Ready Security Module
- session
- Session management for user sessions and authentication.
- state
- Application state management for sharing data across requests.
- static_
files - Static file serving middleware and utilities.
- types
- Common types used throughout the web server abstraction.