| Crates.io | actix-web-validator5 |
| lib.rs | actix-web-validator5 |
| version | 1.0.3 |
| created_at | 2024-04-23 14:51:15.637209+00 |
| updated_at | 2025-03-08 16:22:50.987785+00 |
| description | Validation mechanism for actix-web |
| homepage | |
| repository | https://github.com/chunhui2001/actix-web-validator |
| max_upload_size | |
| id | 1217693 |
| size | 107,295 |
This crate is a Rust library for providing validation mechanism to actix-web with Validator crate
This crate works with Cargo and can be found on
crates.io with a Cargo.toml like:
[dependencies]
actix-web-validator = "5.0.1"
validator = { version = "0.16", features = ["derive"] }
serde = { version = "1", features = ["derive"] }
actix_web::web::Jsonactix_web::web::Queryactix_web::web::Pathactix_web::web::Formserde_qs::actix::QsQueryactix_web versions:0.* supported version of actix-web is 1.*1.* supported version of actix-web is 2.*2.* supported version of actix-web is 3.*3+ supported version of actix-web is 4.*use actix_web::{web, App};
use serde::Deserialize;
use actix_web_validator::Query;
use validator::Validate;
#[derive(Debug, Deserialize)]
pub enum ResponseType {
Token,
Code
}
#[derive(Deserialize, Validate)]
pub struct AuthRequest {
#[validate(range(min = 1000, max = 9999))]
id: u64,
response_type: ResponseType,
}
// Use `Query` extractor for query information (and destructure it within the signature).
// This handler gets called only if the request's query string contains a `id` and
// `response_type` fields.
// The correct request for this handler would be `/index.html?id=1234&response_type=Code"`.
async fn index(info: Query<AuthRequest>) -> String {
format!("Authorization request for client with id={} and type={:?}!", info.id, info.response_type)
}
fn main() {
let app = App::new().service(
web::resource("/index.html").route(web::get().to(index))); // <- use `Query` extractor
}
actix-web-validator is licensed under MIT license (LICENSE or http://opensource.org/licenses/MIT)