Expand description
§vld-actix — Actix-web integration for the vld validation library
Provides extractors that validate request data using vld schemas:
| Extractor | Replaces | Source |
|---|---|---|
VldJson<T> | actix_web::web::Json<T> | JSON request body |
VldQuery<T> | actix_web::web::Query<T> | URL query parameters |
VldPath<T> | actix_web::web::Path<T> | URL path parameters |
VldForm<T> | actix_web::web::Form<T> | URL-encoded form body |
VldHeaders<T> | manual header extraction | HTTP headers |
VldCookie<T> | manual cookie parsing | Cookie values |
All extractors return 422 Unprocessable Entity on validation failure.
§Quick example
ⓘ
use actix_web::{web, App, HttpResponse};
use vld::prelude::*;
use vld_actix::{VldPath, VldQuery, VldJson, VldHeaders};
vld::schema! {
#[derive(Debug)]
pub struct PathParams {
pub id: i64 => vld::number().int().min(1),
}
}
vld::schema! {
#[derive(Debug)]
pub struct Auth {
pub authorization: String => vld::string().min(1),
}
}
vld::schema! {
#[derive(Debug)]
pub struct Body {
pub name: String => vld::string().min(2),
}
}
async fn handler(
path: VldPath<PathParams>,
headers: VldHeaders<Auth>,
body: VldJson<Body>,
) -> HttpResponse {
HttpResponse::Ok().body(format!(
"id={} auth={} name={}",
path.id, headers.authorization, body.name,
))
}Modules§
- prelude
- Prelude — import everything you need.
Structs§
- VldCookie
- Actix-web extractor that validates cookie values from the
Cookieheader. - VldForm
- Actix-web extractor that validates URL-encoded form bodies
(
application/x-www-form-urlencoded). - VldHeaders
- Actix-web extractor that validates HTTP headers.
- VldJson
- Actix-web extractor that validates JSON request bodies.
- VldJson
Error - Error type returned when validation fails.
- VldPath
- Actix-web extractor that validates URL path parameters.
- VldQuery
- Actix-web extractor that validates URL query parameters.