6 stable releases

1.1.2 May 2, 2023
1.1.1 Feb 26, 2023
1.1.0 Dec 1, 2022
1.0.2 Nov 10, 2022

#488 in HTTP server

Download history 63/week @ 2024-07-20 55/week @ 2024-07-27 15/week @ 2024-08-10 18/week @ 2024-08-17 17/week @ 2024-08-24 4/week @ 2024-08-31 4/week @ 2024-09-07 3/week @ 2024-09-14 10/week @ 2024-09-21 10/week @ 2024-09-28 132/week @ 2024-10-05 47/week @ 2024-10-12 17/week @ 2024-10-19 23/week @ 2024-10-26 12/week @ 2024-11-02

122 downloads per month

MIT license

25KB
394 lines

actix-web-jsonschema

Latest Version Documentation GitHub license

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

More information about this crate can be found in the crate documentation.

Installation

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

[dependencies]
actix-web = { version = "4", features = ["macros"] }
actix-web-jsonschema = { version = "1", features = ["validator"] }
serde = { version = "1", features = ["derive"] }
schemars = { version = "0.8" }
validator = { version = "0.16", features = ["derive"] }

Feature Flags

  • validator - provides validator validation.
  • qs_query - provides QsQuery extractor.

Supported extractors

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

Example

use actix_web::{web, App};
use serde::Deserialize;
use schemars::JsonSchema;
use validator::Validate;
use actix_web_jsonschema::Query;

#[derive(Deserialize, JsonSchema, Validate)]
struct Request {
    #[validate(length(min = 1, max = 20))]
    name: String,
}

async fn index(Query(Request{ name }): Query<Request>) -> String {
    format!("Hello, {name}!")
}

fn main() {
    let app = App::new().service(
        web::resource("/hello").route(web::get().to(index))); // <- use `Query` extractor
}

License: MIT

Dependencies

~21–33MB
~584K SLoC