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, route::get, web::Path, Server};
#[handler]
fn hello(Path(name): Path<String>) -> String {
format!("hello: {}", name)
}
#[tokio::main]
async fn main() -> Result<(), std::io::Error> {
let app = route().at("/hello/:name", get(hello));
let listener = TcpListener::bind("127.0.0.1:3000");
let server = Server::new(listener).await?;
server.run(app).await
}
Crate 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 |
tempfile | Support for tempfile |
tower-compat | Adapters for tower::Layer and tower::Service . |
Re-exports
pub use error::Error;
pub use error::Result;
pub use middleware::Middleware;
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.
Component parts of an HTTP Request.
Represents an HTTP response.
An response builder.
Component parts of an HTTP Response.
Routing object for HTTP methods
An HTTP Server.
Traits
An HTTP request handler.
Extension trait for Endpoint
.
Represents a type that can convert into endpoint.
Functions
Create a new routing object.