{"id":15023234,"url":"https://github.com/somehowchris/rocket-validation","last_synced_at":"2025-10-10T10:44:28.394Z","repository":{"id":39662581,"uuid":"446219286","full_name":"somehowchris/rocket-validation","owner":"somehowchris","description":"A guard to validate data received by rocket via validator","archived":false,"fork":false,"pushed_at":"2025-09-18T08:37:07.000Z","size":98,"stargazers_count":17,"open_issues_count":14,"forks_count":7,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-09-18T10:32:00.674Z","etag":null,"topics":["api","rocket","rust","validation","validator","web-api"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/somehowchris.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null},"funding":{"github":["somehowchris"]}},"created_at":"2022-01-09T22:39:04.000Z","updated_at":"2024-12-16T21:41:08.000Z","dependencies_parsed_at":"2024-02-13T16:42:41.621Z","dependency_job_id":"2bd56739-3071-44a8-b44d-0dd2ca1999b2","html_url":"https://github.com/somehowchris/rocket-validation","commit_stats":{"total_commits":55,"total_committers":6,"mean_commits":9.166666666666666,"dds":"0.49090909090909096","last_synced_commit":"7f95655b689161be62446eda57189f71865e2a0a"},"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/somehowchris/rocket-validation","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/somehowchris%2Frocket-validation","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/somehowchris%2Frocket-validation/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/somehowchris%2Frocket-validation/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/somehowchris%2Frocket-validation/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/somehowchris","download_url":"https://codeload.github.com/somehowchris/rocket-validation/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/somehowchris%2Frocket-validation/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279003547,"owners_count":26083595,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-10T02:00:06.843Z","response_time":62,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["api","rocket","rust","validation","validator","web-api"],"created_at":"2024-09-24T19:58:51.564Z","updated_at":"2025-10-10T10:44:28.364Z","avatar_url":"https://github.com/somehowchris.png","language":"Rust","funding_links":["https://github.com/sponsors/somehowchris"],"categories":[],"sub_categories":[],"readme":"# Rocket Validation\n\nWelcome to the Rocket Validation crate. If you are looking to validate your Json, Form or Query structs using Rocket you have come to the right place!\n## Why\nRocket is using Rusts powerful typing system. Which is amazing because you can be sure its what you want. But is it? How about kebab-case strings or phone number inputs, these aren’t really types.\nYou could implement a [custom deserializer](https://docs.serde.rs/serde/de/trait.Deserializer.html) for a wrapped type or write custom logic to validate it on endpoint calls, thats error prone and not ergonomic and doesn't allow you to return meaningful and contextual errors.\n\nIf you are coming from TypeScript you might have heard of [class-validator](https://github.com/typestack/class-validator) which is simple, declarative and can be implemented into middleware. Using [validator](https://github.com/Keats/validator) this crate achieves a similar result using rockets [guard](https://rocket.rs/v0.5-rc/guide/requests/#request-guards) mechanism.\n\u003e Anything implementing [Json](https://rocket.rs/v0.5-rc/guide/requests/#json), [FromRequest](https://rocket.rs/v0.5-rc/guide/requests/#custom-guards) or [FromForm](https://rocket.rs/v0.5-rc/guide/requests/#forms) as well as [`Validate`](https://docs.rs/validator/latest/validator/#example) are able to use the `Validated` guard of this crate, so you can be sure your data is validated once you receive it in your handler.\n\n\u003e Using rockets [catchers](https://rocket.rs/v0.5-rc/guide/requests/#error-catchers) you are able to route errors which occurs during validation to your user.\n\nCurrent validation in rocket: Rocket has validation for FromForm structs but for nothing else.\n\n## Usage\n\nIn order to get going, you need to depend on the `rocket-validation`.\nAdd this to your `Cargo.toml`\n```toml\n[dependencies]\nrocket-validation = \"0.1.3\"\nvalidator=\"?\"\n```\n\u003e `validator` is needed as the derive macros of the crate `validator` generate code dependent on it being available in a global scope\n\nNow you can go on and implement your Validation\n```rust\n// Because we use rocket....\n#[macro_use]\nextern crate rocket;\n\n// Some types for Json types\nuse rocket::serde::{json::Json, Deserialize, Serialize};\n\n// Will be important for validation....\nuse rocket_validation::{Validate, Validated};\n\n#[derive(Debug, Deserialize, Serialize, Validate)] // Implements `Validate`\n#[serde(crate = \"rocket::serde\")]\npub struct HelloData {\n\t#[validate(length(min = 1))] // Your validation annotation\n\tname: String,\n\t#[validate(range(min = 0, max = 100))] // Your validation annotation\n\tage: u8,\n}\n\n#[post(\"/hello\", format = \"application/json\", data = \"\u003cdata\u003e\")]\nfn validated_hello(data: /*Uses the `Validated` type*/ Validated\u003cJson\u003cHelloData\u003e\u003e) -\u003e Json\u003cHelloData\u003e {\n\tJson(data.into_inner())\n}\n\n#[launch]\nfn rocket() -\u003e _ {\n\trocket::build()\n\t\t.mount(\"/\", routes![validated_hello])\n}\n```\n\n### Exposing errors to clients\n\n\u003e Before you use the following, you should be aware of what errors you expose to your clients as well as what that means for security.\n\nIf you would like to respond invalid requests with some custom messages, you can implement the `validation_catcher` catcher to do so.\n```rust\n#[launch]\nfn rocket() -\u003e _ {\n\trocket::build()\n\t\t.mount(\"/\", routes![validated_hello])\n\t\t.register(\"/\", catchers![rocket_validation::validation_catcher])\n}\n```\n\u003e Currently limited to `Json` or `FromData` validations due to inernal rocket limitations\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsomehowchris%2Frocket-validation","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsomehowchris%2Frocket-validation","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsomehowchris%2Frocket-validation/lists"}