Giter Club home page Giter Club logo

actix-web-validator's Introduction

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.2.0"
validator = { version = "0.12", 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.*

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)

actix-web-validator's People

Contributors

andreyermilov avatar c650 avatar nixypanda avatar rlebran avatar roms1383 avatar roxe322 avatar singulared avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.