pub trait Handler: Send + Sync {
// Required method
fn call(
&self,
request: Request<Body>,
request_data: RequestData,
) -> Pin<Box<dyn Future<Output = HandlerResult> + Send + '_>>;
// Provided methods
fn prefers_raw_json_body(&self) -> bool { ... }
fn prefers_parameter_extraction(&self) -> bool { ... }
fn wants_headers(&self) -> bool { ... }
fn wants_cookies(&self) -> bool { ... }
fn wants_request_extensions(&self) -> bool { ... }
fn static_response(&self) -> Option<StaticResponse> { ... }
}Expand description
Handler trait that all language bindings must implement
This trait is completely language-agnostic. Each binding (Python, Node, WASM) implements this trait to bridge their runtime to our HTTP server.
Required Methods§
Sourcefn call(
&self,
request: Request<Body>,
request_data: RequestData,
) -> Pin<Box<dyn Future<Output = HandlerResult> + Send + '_>>
fn call( &self, request: Request<Body>, request_data: RequestData, ) -> Pin<Box<dyn Future<Output = HandlerResult> + Send + '_>>
Handle an HTTP request
Takes the extracted request data and returns a future that resolves to either:
- Ok(Response): A successful HTTP response
- Err((StatusCode, String)): An error with status code and message
Provided Methods§
Sourcefn prefers_raw_json_body(&self) -> bool
fn prefers_raw_json_body(&self) -> bool
Whether this handler prefers consuming RequestData::raw_body over the parsed
RequestData::body for JSON requests.
When true, the server may skip eager JSON parsing when there is no request-body
schema validator attached to the route.
Sourcefn prefers_parameter_extraction(&self) -> bool
fn prefers_parameter_extraction(&self) -> bool
Whether this handler wants to perform its own parameter validation/extraction (path/query/header/cookie).
When true, the server will skip ParameterValidator::validate_and_extract in ValidatingHandler.
This is useful for language bindings which need to transform validated parameters into
language-specific values (e.g., Python kwargs) without duplicating work. When false,
the server stores validated output in RequestData::validated_params.
Sourcefn wants_headers(&self) -> bool
fn wants_headers(&self) -> bool
Whether this handler needs the parsed headers map in RequestData.
When false, the server may skip building RequestData::headers for requests without a body.
(Requests with bodies still typically need Content-Type decisions.)
Whether this handler needs the parsed cookies map in RequestData.
When false, the server may skip parsing cookies for requests without a body.
Sourcefn wants_request_extensions(&self) -> bool
fn wants_request_extensions(&self) -> bool
Whether this handler needs RequestData stored in request extensions.
When false, the server avoids inserting RequestData into extensions to
skip cloning in hot paths.
Sourcefn static_response(&self) -> Option<StaticResponse>
fn static_response(&self) -> Option<StaticResponse>
Return a pre-built static response if this handler always produces the
same output. When Some, the server bypasses the full middleware
pipeline and serves the pre-built response directly.