Expand description
Churust core kernel: the engine, routing, request pipeline, and extractors that power the Churust web framework.
Churust is a Ktor-inspired, async-first web framework for Rust. This crate
(churust-core) is the foundation every other Churust crate builds on. It
provides:
- A fluent
Churust::serverbuilder (AppBuilder) for assembling anAppfrom routes, shared state, middleware, and configuration. - A trie-based
Routersupporting static segments,{param}captures, and trailing{name...}wildcards. - The per-request
Callcontext — the single object every handler receives. - An onion-style middleware pipeline ordered by
Phase. - Type-safe extractors (
Path,Query,State,BearerToken) plus theFromCall/FromCallPartstraits that let handlers take typed arguments. - A flexible
Response/IntoResponsemodel and a status-carryingErrortype. - Layered
Configloading (defaults <churust.toml<CHURUST_*env < code) and optional TLS (featuretls). - An in-process
TestClientfor fast, socket-free integration tests.
§Example
Build an app, register a route, and exercise it with the in-process test client (no socket is bound, so this runs in any environment):
use churust_core::{Churust, Call, TestClient};
let app = Churust::server()
.routing(|r| {
r.get("/", |_c: Call| async { "Hello, Churust!" });
})
.build();
let res = TestClient::new(app).get("/").send().await;
assert_eq!(res.status().as_u16(), 200);
assert_eq!(res.text(), "Hello, Churust!");To actually serve traffic, call App::start (binds a socket and serves
until Ctrl-C) or AppBuilder::start.
Re-exports§
pub use body::Body;pub use error::Error;pub use error::Result;pub use response::IntoResponse;pub use response::Response;pub use call::Call;pub use handler::boxed;pub use handler::BoxHandler;pub use handler::Handler;pub use handler::IntoHandler;pub use state::StateMap;pub use extract::BearerToken;pub use extract::FromCall;pub use extract::FromCallParts;pub use extract::Path;pub use extract::Query;pub use extract::State;pub use router::Match;pub use router::RouteBuilder;pub use router::Router;pub use pipeline::Endpoint;pub use pipeline::Middleware;pub use pipeline::Next;pub use pipeline::Phase;pub use config::Config;pub use config::ServerSection;pub use config::TlsSection;pub use app::App;pub use app::AppBuilder;pub use app::Churust;pub use app::Plugin;pub use app::ServerConfig;pub use ws::WebSocket;pub use ws::WebSocketUpgrade;pub use fs::StaticFiles;pub use test::TestClient;pub use test::TestRequest;pub use test::TestResponse;
Modules§
- app
- Application assembly: the
Churustentry point, theAppBuilderDSL, the immutableApp, thePlugintrait, and the resolvedServerConfig. - body
- The response
Body: either a fully-bufferedBytespayload or a lazy stream of byte chunks (for files, large/dynamic responses, SSE, etc.). - call
- The per-request
Callcontext — the single object every handler receives. - config
- Layered configuration: defaults <
churust.toml< env (CHURUST_*) < code. - engine
- The hyper-based HTTP/1.1 serving engine that drives an
Appover a real socket. - error
- The status-carrying
Errortype and the crate-wideResultalias. - extract
- Extractors: typed handler arguments derived from a
Call. - fs
- Static file serving (feature
fs). - handler
- Handlers: the
Handlertrait, handler closures, and the glue that turns extractor closures into stored handlers. - pipeline
- The request pipeline:
Middleware, thePhaseordering, theNextcontinuation, and theEndpointterminal. - response
- The buffered
Responsetype and theIntoResponseconversion trait. - router
- The trie-based
Router, itsMatchresult, and theRouteBuilderDSL used insideAppBuilder::routing. - state
- Type-keyed shared application state (a minimal DI registry).
- test
- In-process test harness. Drives
App::processdirectly — no socket bind. - tls
- TLS support (feature
tls). Loads a PEM cert chain + private key and builds atokio_rustls::TlsAcceptorwith rustls’ safe defaults. - ws
- WebSocket support (feature
ws).