Expand description
§vld-tower — Tower middleware for vld validation
A universal [tower::Layer] that validates incoming HTTP JSON request
bodies against a vld schema. Works with any Tower-compatible
framework: Axum, Hyper, Tonic, Warp, etc.
On success the validated struct is stored in
http::Request::extensions so downstream handlers can retrieve it
without re-parsing. The original body bytes are forwarded as-is.
On failure a 422 Unprocessable Entity JSON response is returned
immediately — the inner service is never called.
§Quick Start (with Axum)
use vld::prelude::*;
use vld_tower::ValidateJsonLayer;
vld::schema! {
#[derive(Debug, Clone)]
pub struct CreateUser {
pub name: String => vld::string().min(2).max(100),
pub email: String => vld::string().email(),
}
}
// Apply as a layer — works with any Tower-based router
// let app = Router::new()
// .route("/users", post(handler))
// .layer(ValidateJsonLayer::<CreateUser>::new());Modules§
- prelude
- Prelude — import everything you need.
Structs§
- Validate
Json Layer - A
tower_layer::Layerthat validates JSON request bodies withvld. - Validate
Json Service - The middleware
Servicecreated byValidateJsonLayer.
Functions§
- try_
validated - Try to extract the validated value from request extensions.
- validated
- Extract the validated value from request extensions.