10 releases (5 stable)

2.0.3 Jan 12, 2021
2.0.2 Dec 28, 2020
2.0.1 Sep 27, 2020
1.0.0 Jun 6, 2020
0.1.2 Feb 28, 2020

#65 in Web programming

Download history 69/week @ 2020-10-02 98/week @ 2020-10-09 80/week @ 2020-10-16 52/week @ 2020-10-23 119/week @ 2020-10-30 76/week @ 2020-11-06 94/week @ 2020-11-13 75/week @ 2020-11-20 75/week @ 2020-11-27 69/week @ 2020-12-04 56/week @ 2020-12-11 64/week @ 2020-12-18 31/week @ 2020-12-25 57/week @ 2021-01-01 204/week @ 2021-01-08 214/week @ 2021-01-15

318 downloads per month

MIT license

27KB
370 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 = "2.0.3"

Supported actix_web::web extractors:

  • web::Json
  • web::Query
  • web::Path

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.*

Example:

use actix_web::{web, App};
use serde_derive::Deserialize;
use actix_web_validator::{Query, 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

~20MB
~480K SLoC