14 releases (9 stable)

Uses new Rust 2021

3.0.0 Mar 15, 2022
2.2.0 Oct 4, 2021
2.1.1 Jun 7, 2021
2.0.3 Jan 12, 2021
0.1.2 Feb 28, 2020

#97 in Web programming

Download history 225/week @ 2022-03-06 648/week @ 2022-03-13 419/week @ 2022-03-20 510/week @ 2022-03-27 756/week @ 2022-04-03 771/week @ 2022-04-10 624/week @ 2022-04-17 647/week @ 2022-04-24 736/week @ 2022-05-01 580/week @ 2022-05-08 891/week @ 2022-05-15 486/week @ 2022-05-22 638/week @ 2022-05-29 751/week @ 2022-06-05 533/week @ 2022-06-12 521/week @ 2022-06-19

2,492 downloads per month
Used in paperclip

MIT license

40KB
554 lines

actix-web-validator Latest Version Documentation Coverage Build Status

This crate is a Rust library for providing validation mechanism to actix-web with Validator crate

Installation

This crate works with Cargo and can be found on crates.io with a Cargo.toml like:

[dependencies]
actix-web-validator = "3.0.0"
validator = { version = "0.14", features = ["derive"] }
serde = { version = "1", features = ["derive"] }

Supported extractors:

  • actix_web::web::Json
  • actix_web::web::Query
  • actix_web::web::Path
  • actix_web::web::Form
  • serde_qs::actix::QsQuery

Supported actix_web versions:

  • For actix-web-validator 0.* supported version of actix-web is 1.*
  • For actix-web-validator 1.* supported version of actix-web is 2.*
  • For actix-web-validator 2.* supported version of actix-web is 3.*
  • For actix-web-validator 3.* supported version of actix-web is 4.*

Example:

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
}

License

actix-web-validator is licensed under MIT license (LICENSE or http://opensource.org/licenses/MIT)

Dependencies

~15–23MB
~528K SLoC