vld-warp
Warp integration for the vld validation library.
Features
| Filter / Function | Source | Description |
|---|---|---|
vld_json::<T>() |
JSON body | Validates JSON request body |
vld_query::<T>() |
Query string | Validates URL query parameters |
vld_form::<T>() |
Form body | Validates URL-encoded form body |
vld_param::<T>(name) |
Single path segment | Validates one URL path segment |
vld_path::<T>(names) |
Path tail | Validates all remaining path segments |
validate_path_params::<T>(pairs) |
Pre-extracted params | Validates mixed static/dynamic path segments |
vld_headers::<T>() |
HTTP headers | Validates request headers |
vld_cookie::<T>() |
Cookie header | Validates cookie values |
handle_rejection |
— | Converts vld rejections into JSON responses |
Validation failures are returned as 422 Unprocessable Entity with a JSON error body.
Installation
[]
= "0.1"
= "0.1"
= "0.3"
= "1"
Quick Start
use *;
use Filter;
schema!
async
Path Parameters
Warp doesn't have a built-in named path parameter extractor. vld-warp
provides three approaches to fill this gap.
vld_param — single segment
Extracts one path segment and validates it. The name argument
becomes the JSON key so it matches your schema's field name.
schema!
// GET /users/<id>
let route = path
.and
.and
.map;
vld_path — all remaining segments (tail)
Consumes all remaining path segments via warp::path::tail() and
maps them 1-to-1 to the provided names. The segment count must match
the name count exactly (otherwise → 404).
Best for routes where all remaining segments are dynamic.
schema!
// GET /posts/<user_id>/<post_id>
let route = path
.and
.map;
validate_path_params — mixed static / dynamic
For complex routes with interleaved static and dynamic segments, extract
each String segment with warp::path::param::<String>() yourself,
then call validate_path_params in and_then to validate them all at
once.
schema!
// GET /users/<uid>/posts/<pid>/comments/<cid>
let route = path
.and
.and
.and
.and
.and
.and
.and_then;
Recovery Handler
Always add .recover(handle_rejection) to convert vld rejections into structured JSON:
let routes = create.or.recover;
Error response format:
Running Examples
Example Requests
# Create user (valid)
# Create user (invalid — triggers 422)
# Get user by id (vld_param)
# Invalid user id (vld_param — triggers 422)
# Get post (vld_path — tail params)
# Get comment (validate_path_params — mixed segments)
# Search (query params)
# Health check
License
MIT