Expand description
Core framework of the jerrycan platform: routing, extractors, dependency
injection, middleware. Generated apps import this through the jerrycan
facade crate — see https://jerrycan.cc
Re-exports§
pub use app::App;pub use app::BuiltApp;pub use app::Extension;pub use clock::Clock;pub use cors::CorsConfig;pub use cors::CorsOrigins;pub use dep::Dep;pub use dep::TaskContext;pub use error::Error;pub use error::Result;pub use extract::FromRequest;pub use extract::Headers;pub use extract::Path;pub use extract::Query;pub use extract::RawBody;pub use extract::RequestCtx;pub use handler::Handler;pub use middleware::Middleware;pub use middleware::MiddlewareFuture;pub use middleware::Next;pub use module::Module;pub use multipart::Multipart;pub use response::BodyError;pub use response::BodySender;pub use response::Created;pub use response::IntoResponse;pub use response::JcBody;pub use response::Json;pub use response::NoContent;pub use response::Redirect;pub use response::Response;pub use response::StreamBody;pub use router::MethodRouter;pub use router::delete;pub use router::get;pub use router::patch;pub use router::post;pub use router::put;pub use test_client::TestApp;pub use test_client::TestPart;pub use test_client::TestResponse;pub use http;pub use serde_urlencoded;
Modules§
- app
App(spec §4.1): assembles mounted modules + app-level routes, validates the route table at build time (fail loud), and dispatches requests.- clock
- Injectable time. Handlers/extensions take
Dep<Clock>and callnow(); tests control it viaTestApp::clock().advance(..). The serve engine’s own timeouts deliberately stay on real tokio time — Clock is for DOMAIN time (rate windows, schedules, expiry), not transport timeouts. - cors
- CORS (spec §v2.2). Lives in core because preflight must be answered BEFORE
routing (an
OPTIONSto a method-mismatched route is rejected 405 before any middleware runs), so CORS is a pre-routing + response-decoration concern integrated intoroute_policy/dispatch in later tasks — not aMiddleware. - dep
- Dependency injection (spec §4.3) — async, nested, per-request memoized,
override-able in tests. Resolution order: cache → overrides → singletons → factories.
Singletons and factories are disjoint by construction (
insert_value/insert_factoryeach remove the opposite key), so there is no singleton-vs-factory tiebreak to define. - error
- jerrycan’s single error type. Every error carries a stable
code(JC####) that maps to a documentation anchor — the error-driven-docs contract (spec §8). - extract
- Request context and extractors (spec §4.1). Everything a handler needs is
visible in its signature; each parameter implements
FromRequest. - handler
- Handler abstraction (spec §4.1): a handler is a plain async fn whose
parameters implement
FromRequestand whose return implementsIntoResponse. Extraction failures short-circuit into error responses. - middleware
- Middleware (spec §4.1):
async fn handle(&self, ctx, next). Composable, ordering explicit, no tower, no magic. - module
Module(spec §4.2): the unit of routing, packaging, and ownership. Bundles routes, nested subroutes, module-scoped dependencies and middleware. Flattening composes URL prefixes and layers environments (inner wins).- multipart
multipart/form-data(RFC 7578). The parser half is a pure incremental state machine — fed chunks, drained as events, no IO — so the grammar is unit-testable at every chunk straddle and fuzzable in isolation (fuzz/fuzz_targets/multipart_parse.rs). The extractor half (Task 7) adapts it to the request body lanes.- prelude
- One import for generated code:
use jerrycan::prelude::*; - response
- Response model. Handlers return anything implementing
IntoResponse;Result<T, Error>renders errors as{"code","message"}JSON (spec §4.1). - router
- Method routing + segment trie with
{param}captures (spec §4.1). Conflicting routes are detected at build time — fail loud before serving. Path segments are percent-decoded after ‘/’-splitting; malformed encodings surface asRouteMatch::Malformed(a clean 400, never a panic). - test_
client - In-memory test client (spec §4.1 “Test client”): no sockets, no network.
override_depis THE testing seam — fake any dependency, run real requests.
Macros§
- path_
param - Admit a custom newtype as a
Pathparameter. The type must implementFromStrwith aDisplayerror; a parse failure maps to the sameJC0400invalid-path-parameter error the built-in impls produce.