actix-web-validator
cargo install actix-web-validator

actix-web-validator

Rust library for providing validation mechanism to actix-web with Validator crate.

by rambler-digital-solutions

2.0.1 (see all)License:MIT
cargo install actix-web-validator
Readme

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.1"

Supported actix_web::web extractors:

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

Supported actix_web versions:

  • For actix-web-validator < 1.0 supported version of actix-web is 1.*
  • For actix-web-validator >= 1.0 supported version of actix-web is 2.*
  • For actix-web-validator >= 2.0 supported version of actix-web is 3.*

Example:

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

GitHub Stars

38

LAST COMMIT

9mos ago

MAINTAINERS

2

CONTRIBUTORS

9

OPEN ISSUES

2

OPEN PRs

1
VersionTagPublished
2.0.1
2yrs ago
2.0.0
2yrs ago
1.0.0
2yrs ago
0.2.1
2yrs ago
No alternatives found
No tutorials found
Add a tutorial