vld-rocket 0.7.1

DEPRECATED: moved to vld-web 0.8 (vld_web::rocket). Rocket integration for the vld validation library
Documentation

vld-rocket

Deprecated. vld-rocket is not developed any more. Since vld 0.8 it is part of vld-web: vld_web::rocket.

vld-web = { version = "0.8", features = ["rocket"] }

Migration guide: https://s00d.github.io/vld/guides/migration#from-07-to-08. This version (0.7.1) is 0.7.0 unchanged, with this notice.

crates.io docs.rs

Rocket 0.5 guards that validate JSON bodies, query strings, path segments, forms, headers and cookies with vld schemas, plus catchers that answer with JSON errors.

Install

[dependencies]
vld = "0.5"
vld-rocket = "0.5"
rocket = { version = "0.5", features = ["json"] }

Example

use vld_rocket::prelude::*;

vld::schema! {
    #[derive(Debug, Clone)]
    pub struct CreateUser {
        pub name: String  => vld::string().min(2).max(50),
        pub email: String => vld::string().email(),
    }
}

#[rocket::post("/users", data = "<user>")]
fn create_user(user: VldJson<CreateUser>) -> String {
    format!("created {}", user.name)
}

#[rocket::launch]
fn rocket() -> _ {
    rocket::build()
        .mount("/", rocket::routes![create_user])
        .register("/", vld_catchers()) // JSON bodies for 400, 413, 415, 422
}

Invalid input is answered with 422 and {"error": "Validation failed", "issues": [{"path": ".name", "message": "...", "code": "too_small"}]}; a wrong Content-Type is 415, a body over the limit is 413. Bodies are limited by Rocket's json / form limits; while those are at Rocket's built-in defaults, 2 MiB applies.

Guards: VldJson, VldForm, VldQuery, VldPath, VldHeaders, VldCookie.

Documentation

MSRV: 1.85 (MSRV.md).

License

MIT