web_server_abstraction/
lib.rs

1//! # Web Serve/// ## Supported Frameworks
2//!
3//! - Mock (for testing)
4//! - Axum
5//! - Actix-Web
6//! - Warpction
7//!
8//! An ergonomic abstraction layer over popular Rust web frameworks.
9//!
10//! This crate provides a unified interface for building web applications that can
11//! run on multiple web frameworks without changing your application code.
12//!
13//! ## Features
14//!
15//! - **Framework Agnostic**: Write once, run on any supported framework
16//! - **Type Safe**: Leverages Rust's type system for compile-time guarantees
17//! - **Async First**: Built for modern async Rust
18//! - **Middleware Support**: Composable middleware system
19//! - **Tower Integration**: Built on the Tower ecosystem
20//!
21//! ## Supported Frameworks
22//!
23//! - Axum
24//! - Actix-Web
25//! - Rocket
26//! - Warp
27//! - Salvo
28//! - Poem
29//!
30//! ## Quick Start
31//!
32//! ```rust,no_run
33//! use web_server_abstraction::{WebServer, Route, HttpMethod, Response};
34//!
35//! #[tokio::main]
36//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
37//!     let server = WebServer::new()
38//!         .route("/hello", HttpMethod::GET, |_req| async {
39//!             Ok(Response::ok().body("Hello, World!"))
40//!         })
41//!         .bind("127.0.0.1:3000")
42//!         .await?;
43//!
44//!     server.run().await?;
45//!     Ok(())
46//! }
47//! ```
48
49pub mod adapters;
50pub mod auth;
51pub mod benchmarks;
52pub mod content;
53pub mod core;
54pub mod database;
55pub mod error;
56pub mod middleware;
57pub mod mountable;
58pub mod routing;
59pub mod security;
60pub mod session;
61pub mod state;
62pub mod static_files;
63pub mod types;
64
65// Re-export core types
66pub use auth::{
67    auth_middleware, enhanced_auth_middleware, AuthContext, AuthContextConfig, AuthError,
68    AuthMiddlewareResult, AuthRequirements, RequestAuthExt, UserSession,
69};
70pub use core::{Handler, HandlerFn, Route, WebServer};
71pub use error::{Result, WebServerError};
72pub use types::{
73    Cookie, FileUpload, Headers, HttpMethod, MultipartForm, Request, Response, StatusCode,
74};
75
76// Re-export new modules
77pub use content::{CompressionMiddleware, ContentNegotiationMiddleware};
78pub use database::{
79    ConnectionPool, DatabaseConfig, DatabaseConnection, DatabaseError, DatabaseValue,
80    FromDatabaseValue, MockDatabase, PoolStats, QueryBuilder, Row, Transaction,
81};
82pub use mountable::{
83    InterfaceBuilder, InterfaceRegistry, MountOptions, MountableInterface, OpenApiSpec,
84    RouteDefinition, RouteDoc,
85};
86pub use routing::{Route as RoutePattern, Router};
87pub use security::{sanitize, CspMiddleware, CsrfMiddleware, XssProtectionMiddleware};
88pub use session::{MemorySessionStore, Session, SessionExt, SessionManager, SessionStore};
89pub use state::{AppState, Config, Environment, SharedState};
90pub use static_files::{
91    serve_static, serve_static_with_prefix, static_files, StaticFileConfig, StaticFileHandler,
92};
93
94// Re-export benchmarking utilities
95pub use benchmarks::{BenchmarkConfig, BenchmarkResults, PerformanceProfiler};
96
97// Re-export framework adapters when features are enabled
98pub use adapters::mock::MockAdapter;
99
100#[cfg(feature = "axum")]
101pub use adapters::axum::AxumAdapter;
102
103#[cfg(feature = "actix-web")]
104pub use adapters::actix_web::ActixWebAdapter;
105
106#[cfg(feature = "warp")]
107pub use adapters::warp::WarpAdapter;
108
109#[cfg(feature = "rocket")]
110pub use adapters::rocket::RocketAdapter;
111
112#[cfg(feature = "salvo")]
113pub use adapters::salvo::SalvoAdapter;
114
115#[cfg(feature = "poem")]
116pub use adapters::poem::PoemAdapter;