actix_web_validator/
lib.rs

1//! *actix-web-validator* is a crate for providing validation mechanism to actix-web with *validator* crate.
2//!
3//! The main idea of this crate is to add full validation support provided by validator derive traits
4//! and provide maximum compatibility with base `actix_web::web::{Query, Json, Path}` structures.
5//!
6//! ## Example
7//!
8//! ```rust
9//! use actix_web::{web, App};
10//! use serde::Deserialize;
11//! use actix_web_validator::Query;
12//! use validator::Validate;
13//!
14//! #[derive(Debug, Deserialize)]
15//! pub enum ResponseType {
16//!     Token,
17//!     Code
18//! }
19//!
20//! #[derive(Deserialize, Validate)]
21//! pub struct AuthRequest {
22//!     #[validate(range(min = 1000, max = 9999))]
23//!     id: u64,
24//!     response_type: ResponseType,
25//! }
26//!
27//! // Use `Query` extractor for query information (and destructure it within the signature).
28//! // This handler gets called only if the request's query string contains a `id` and
29//! // `response_type` fields.
30//! // The correct request for this handler would be `/index.html?id=19&response_type=Code"`.
31//! async fn index(info: Query<AuthRequest>) -> String {
32//!     assert!(info.id >= 1000);
33//!     format!("Authorization request for client with id={} and type={:?}!", info.id, info.response_type)
34//! }
35//!
36//! fn main() {
37//!     let app = App::new().service(
38//!        web::resource("/index.html").route(web::get().to(index))); // <- use `Query` extractor
39//! }
40//! ```
41pub mod error;
42mod form;
43mod json;
44mod path;
45mod qsquery;
46mod query;
47pub use error::Error;
48pub use form::*;
49pub use json::*;
50pub use path::*;
51pub use qsquery::*;
52pub use query::*;