# Poem — Full-Featured Async Web Framework for Rust > A fast and elegant Rust web framework with built-in OpenAPI generation, middleware, and session management powered by Tokio and Hyper. ## Install Save in your project root: # Poem — Full-Featured Async Web Framework for Rust ## Quick Use ```rust use poem::{get, handler, listener::TcpListener, Route, Server}; #[handler] fn hello() -> String { "Hello, World!".to_string() } #[tokio::main] async fn main() -> Result<(), std::io::Error> { let app = Route::new().at("/", get(hello)); Server::new(TcpListener::bind("0.0.0.0:3000")) .run(app).await } ``` ## Introduction Poem is a full-featured async web framework for Rust that prioritizes developer ergonomics without sacrificing performance. Built on Tokio and Hyper, it provides extractors, middleware, OpenAPI spec generation, and WebSocket support in a single cohesive package — filling the gap between minimalist frameworks and heavy enterprise stacks. ## What Poem Does - Routes HTTP requests to async handler functions with type-safe extractors - Generates OpenAPI 3.0 documentation from code annotations automatically - Provides middleware for logging, CORS, compression, rate limiting, and auth - Supports WebSocket, SSE (Server-Sent Events), and multipart uploads - Integrates with Tower middleware ecosystem for reuse ## Architecture Overview Poem uses a layered architecture: a Router dispatches requests to Endpoints (handlers). Extractors pull typed data from requests (path params, query strings, JSON bodies). Middleware wraps endpoints for cross-cutting concerns. The OpenAPI module uses proc macros to derive schema definitions from Rust types at compile time, producing a spec without runtime reflection. ## Self-Hosting & Configuration - Add to Cargo.toml: `poem = "3"` and `poem-openapi = "5"` - Define routes with method-specific macros (get, post, put, delete) - Configure TLS via poem with rustls or native-tls feature flags - Deploy as a single static binary — no runtime dependencies - Use tracing integration for structured logging ## Key Features - Compile-time OpenAPI spec generation from handler signatures - Type-safe parameter extraction with helpful compile errors - Built-in session management with cookie and Redis backends - First-class WebSocket support with typed messages - Graceful shutdown handling for zero-downtime deploys ## Comparison with Similar Tools - **Axum** — Also Tokio-based, more minimal; Poem has built-in OpenAPI and sessions - **Actix Web** — Higher raw throughput; Poem offers better ergonomics and compile times - **Rocket** — Synchronous by default (v0.5 adds async); Poem is async-first - **Warp** — Filter-based composition; Poem uses more traditional routing patterns ## FAQ **Q: How does Poem compare to Axum in performance?** A: Both use Hyper/Tokio and have nearly identical throughput. The difference is in API surface — Poem bundles more features while Axum is more composable. **Q: Can I use Poem with SQLx or Diesel?** A: Yes. Pass a database pool as shared state via Data extractor, then use it in any handler. **Q: Does Poem support gRPC?** A: Not directly. Use tonic alongside Poem, or route gRPC traffic separately. Poem focuses on HTTP/REST and WebSocket. **Q: How mature is Poem for production use?** A: Poem is stable with semantic versioning. It powers production services handling high request volumes. The ecosystem is smaller than Actix or Axum but growing. ## Sources - https://github.com/poem-web/poem - https://docs.rs/poem/latest/poem/ --- Source: https://tokrepo.com/en/workflows/asset-949ba1c9 Author: AI Open Source