Back to Poem

README

poem/README.md

2.0.06.4 KB
Original Source
<h1 align="center">Poem Framework</h1> <div align="center"> <!-- Crates version --> <a href="https://crates.io/crates/poem"> </a> <!-- Downloads --> <a href="https://crates.io/crates/poem"> </a> <!-- docs.rs docs --> <a href="https://docs.rs/poem"> </a> <a href="https://github.com/rust-secure-code/safety-dance/"> </a> <a> </a> <a href="https://discord.gg/qWWNxwasb7"> </a> </div> <p align="center"><code>A program is like a poem, you cannot write a poem without writing it. --- Dijkstra</code></p> <p align="center"> A full-featured and easy-to-use web framework with the Rust programming language.</p>

Features

  • Both Ease of use and performance.
  • Minimizing the use of generics.
  • Blazing fast and flexible routing.
  • tower::Service and tower::Layer compatibility.
  • Use poem-openapi to write APIs that comply with OAS3 specifications and automatically generate documents.

Crate features

To avoid compiling unused dependencies, Poem gates certain features, all of which are disabled by default:

FeatureDescription
serverServer and listener APIs (enabled by default)
compressionSupport decompress request body and compress response body
cookieSupport for Cookie
csrfSupport for Cross-Site Request Forgery (CSRF) protection
multipartSupport for Multipart
native-tlsSupport for HTTP server over TLS with native-tls
openssl-tlsSupport for HTTP server over TLS with openssl-tls
opentelemetrySupport for opentelemetry
prometheusSupport for Prometheus
redis-sessionSupport for RedisSession
rustlsSupport for HTTP server over TLS with rustls
sessionSupport for session
sseSupport Server-Sent Events (SSE)
static-filesSupport static files endpoint
tempfileSupport for tempfile
tower-compatAdapters for tower::Layer and tower::Service.
websocketSupport for WebSocket
anyhowIntegrate with anyhow crate.
eyre06Integrate with version 0.6.x of the eyre crate.
i18nSupport for internationalization
acme-native-rootsSupport for ACME(Automatic Certificate Management Environment)
acme-webpki-rootsSupport for ACME using webpki TLS roots rather than native TLS roots
tokio-metricsIntegrate with tokio-metrics crate.
embedIntegrate with rust-embed crate.
xmlIntegrate with quick-xml crate.
yamlIntegrate with serde-yaml crate.
requestidAssociates an unique ID with each incoming request
sonic-rsUses sonic-rs instead of serde_json. Pls, checkout sonic-rs requirements to properly enable sonic-rs capabilities

Safety

This crate uses #![forbid(unsafe_code)] to ensure everything is implemented in 100% Safe Rust.

Example

rust,
use poem::{get, handler, listener::TcpListener, web::Path, Route, Server};

#[handler]
fn hello(Path(name): Path<String>) -> String {
    format!("hello: {}", name)
}

#[tokio::main]
async fn main() -> Result<(), std::io::Error> {
    let app = Route::new().at("/hello/:name", get(hello));
    Server::new(TcpListener::bind("0.0.0.0:3000"))
      .run(app)
      .await
}

More examples can be found here.

MSRV

The minimum supported Rust version for this crate is 1.85.0.

Contributing

:balloon: Thanks for your help improving the project! We are so happy to have you!

License

Licensed under either of

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in Poem by you, shall be licensed as Apache, without any additional terms or conditions.