Crate web_server_abstraction

Crate web_server_abstraction 

Source
Expand description

§Web Serve/// ## Supported Frameworks

  • Mock (for testing)
  • Axum
  • Actix-Web
  • Warpction

An ergonomic abstraction layer over popular Rust web frameworks.

This crate provides a unified interface for building web applications that can run on multiple web frameworks without changing your application code.

§Features

  • Framework Agnostic: Write once, run on any supported framework
  • Type Safe: Leverages Rust’s type system for compile-time guarantees
  • Async First: Built for modern async Rust
  • Middleware Support: Composable middleware system
  • Tower Integration: Built on the Tower ecosystem

§Supported Frameworks

  • Axum
  • Actix-Web
  • Rocket
  • Warp
  • Salvo
  • Poem

§Quick Start

use web_server_abstraction::{WebServer, Route, 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, World!"))
        })
        .bind("127.0.0.1:3000")
        .await?;

    server.run().await?;
    Ok(())
}

Re-exports§

pub use auth::auth_middleware;
pub use auth::enhanced_auth_middleware;
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 core::Handler;
pub use core::HandlerFn;
pub use core::Route;
pub use core::WebServer;
pub use error::Result;
pub use error::WebServerError;
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;
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 security::sanitize;
pub use security::CspMiddleware;
pub use security::CsrfMiddleware;
pub use security::XssProtectionMiddleware;
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 state::SharedState;
pub use static_files::serve_static;
pub use static_files::serve_static_with_prefix;
pub use static_files::static_files;
pub use static_files::StaticFileConfig;
pub use static_files::StaticFileHandler;
pub use benchmarks::BenchmarkConfig;
pub use benchmarks::BenchmarkResults;
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.
content
Content negotiation and advanced content handling.
core
Core traits and types for the web server abstraction.
database
Database integration helpers.
error
Error types for the web server abstraction.
middleware
Expanded middleware implementations with advanced features.
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.
routing
security
Advanced security middleware for CSRF, XSS protection, and more.
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.