Expand description
§vld-ntex — ntex integration for the vld validation library
Provides extractors that validate request data using vld schemas:
| Extractor | Replaces | Source |
|---|---|---|
VldJson<T> | ntex::web::types::Json<T> | JSON request body |
VldQuery<T> | ntex::web::types::Query<T> | URL query parameters |
VldPath<T> | ntex::web::types::Path<T> | URL path parameters |
VldForm<T> | ntex::web::types::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 ntex::web::{self, App, HttpResponse};
use vld::prelude::*;
use vld_ntex::{VldJson, VldQuery, VldPath, VldHeaders};
vld::schema! {
#[derive(Debug)]
pub struct PathParams {
pub id: i64 => vld::number().int().min(1),
}
}
vld::schema! {
#[derive(Debug)]
pub struct Body {
pub name: String => vld::string().min(2),
}
}
async fn handler(
path: VldPath<PathParams>,
body: VldJson<Body>,
) -> HttpResponse {
HttpResponse::Ok().body(format!("id={} name={}", path.id, body.name))
}Modules§
- prelude
- Prelude — import everything you need.
Structs§
- VldCookie
- ntex extractor that validates cookie values from the
Cookieheader. - VldForm
- ntex extractor that validates URL-encoded form bodies
(
application/x-www-form-urlencoded). - VldHeaders
- ntex extractor that validates HTTP headers.
- VldJson
- ntex extractor that validates JSON request bodies.
- VldNtex
Error - Error type returned when validation fails.
- VldPath
- ntex extractor that validates URL path parameters.
- VldQuery
- ntex extractor that validates URL query parameters.