Expand description
§Rpress
A lightweight async HTTP/1.1 and HTTP/2 framework built on tokio.
Rpress provides routing, middleware, request body streaming, response compression,
CORS (with fail-fast RFC validation), pluggable rate limiting (via RateLimiter trait),
granular body size limits (global and per route group), static file serving,
native TLS (via rustls), and HTTP/2 (via h2 with automatic ALPN negotiation) out of the box.
§Quick Start
use rpress::{Rpress, RpressCors, RpressRoutes, RequestPayload, ResponsePayload};
#[tokio::main]
async fn main() -> anyhow::Result<()> {
let mut app = Rpress::new(None);
let mut routes = RpressRoutes::new();
routes.add(":get/hello", |_req: RequestPayload| async {
ResponsePayload::text("Hello, world!")
});
app.add_route_group(routes);
app.listen("0.0.0.0:3000").await
}§TLS (HTTPS) and HTTP/2
Use RpressTlsConfig and Rpress::listen_tls to serve over HTTPS.
HTTP/2 is negotiated automatically via ALPN when clients support it.
use rpress::{Rpress, RpressTlsConfig, RpressRoutes, RequestPayload, ResponsePayload};
#[tokio::main]
async fn main() -> anyhow::Result<()> {
let mut app = Rpress::new(None);
let mut routes = RpressRoutes::new();
routes.add(":get/hello", |_req: RequestPayload| async {
ResponsePayload::text("Hello, HTTPS!")
});
app.add_route_group(routes);
let tls = RpressTlsConfig::from_pem("cert.pem", "key.pem")?;
app.listen_tls("0.0.0.0:443", tls).await
}Re-exports§
pub use core::cors::RpressCors;pub use core::error::RpressEngineError;pub use core::handler_response::CookieBuilder;pub use core::handler_response::IntoRpressResult;pub use core::handler_response::ResponsePayload;pub use core::handler_response::RpressError;pub use core::handler_response::RpressErrorExt;pub use core::routes::RpressRoutes;pub use core::tls::RpressTlsConfig;pub use core::rate_limiter::RateLimiter;pub use core::rate_limiter::InMemoryRateLimiter;pub use types::definitions::RequestPayload;pub use types::definitions::RpressResult;pub use types::definitions::StatusCode;
Modules§
Macros§
- handler
- Macro to create a handler closure from a controller method.
Structs§
- Rpress
- Async HTTP/1.1 server with routing, middleware, compression, and more.