Crate actix_web_jsonschema
source ·Expand description
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
Supported extractors
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
}
Structs
- Form can be used for extracting typed information and validation from request’s form data.
- Json can be used for exstracting typed information and validation from request’s payload.
- Extract typed information from the request’s path.
- Extract and validate typed information from the request’s query (serde_qs based).
- Extract and validate typed information from the request’s query.