vld-tower
Universal Tower middleware for validating HTTP JSON request bodies with vld. Works with any Tower-compatible framework: Axum, Hyper, Tonic, Warp, etc.
Installation
[]
= "0.1"
= "0.1"
How it Works
- Intercepts incoming HTTP requests with
Content-Type: application/json - Reads the body and validates against a
vldschema - Valid — stores the parsed struct in request extensions, passes request to the inner service
- Invalid — returns
422 Unprocessable Entitywith JSON error details; inner service is never called - Non-JSON requests pass through untouched
Quick Start
use ;
use ServiceBuilder;
schema!
// Apply as a Tower layer
let svc = new
.layer
.service_fn;
Extracting Validated Data
use ;
async .>, ...>
With Axum
use ;
use ValidateJsonLayer;
let app = new
.route
.layer;
Error Responses
Validation Error (422)
Malformed JSON (400)
Running the Example
License
MIT