Crate poem[−][src]
Expand description
Poem is a full-featured and easy-to-use web framework with the Rust programming language.
Usage
Depend on poem in Cargo.toml:
poem = "*"
Example
use poem::{handler, listener::TcpListener, route, web::Path, Server};
#[handler]
fn hello(Path(name): Path<String>) -> String {
format!("hello: {}", name)
}
#[tokio::main]
async fn main() {
use poem::route::get;
let app = route().at("/hello/:name", get(hello));
let listener = TcpListener::bind("127.0.0.1:3000");
let server = Server::new(listener).await.unwrap();
server.run(app).await.unwrap();
}
Features
To avoid compiling unused dependencies, Poem gates certain features, all of which are disabled by default:
Feature | Description |
---|---|
websocket | Support for WebSocket |
multipart | Support for Multipart |
sse | Support Server-Sent Events (SSE) |
tls | Support for HTTP server over TLS |
typed-headers | Support for typed-headers |
tracing | Support for Tracing middleware |
tempfile | Support for tempfile |
Re-exports
pub use error::Error;
pub use error::Result;
pub use middleware::Middleware;
pub use route::route;
pub use route::RouteMethod;
pub use web::FromRequest;
pub use web::IntoResponse;
pub use web::RequestBody;
Modules
Endpoint related types.
Some common error types.
A general purpose library of common HTTP types
Commonly used listeners.
Commonly used middleware.
Route object and DSL
Some commonly used services that implement
Endpoint
.
Commonly used as the type of extractor or response.
Structs
A body object for requests and responses.
Represents an HTTP request.
An request builder.
Represents an HTTP response.
An response builder.
An HTTP Server.
Traits
An HTTP request handler.
Extension trait for Endpoint
.
Represents a type that can convert into endpoint.