Crate axum_serde_valid

source ·
Expand description

Latest Version Documentation GitHub license

This crate is a Rust library for providing validation mechanism to axum with serde_valid 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]
axum = "0.6"
axum_serde_valid = { version = "13", features = ["jsonschema"] }
jsonschema  = "^0.16"
schemars  = "0.8"

§Example

use axum::{routing::post, Router};
use axum_serde_valid::Json;
use serde::Deserialize;
use serde_valid::Validate;

#[derive(Deserialize, Validate)]
struct User {
    #[validate(max_length = 3)]
    name: String,
}

let app = Router::<()>::new().route("/json", post(|user: Json<User>| async move { "hello" }));

Modules§

Structs§

  • Wrapper type over axum::Json that validates requests and responds with a more helpful validation message.