Actix Web Validation
Request validation for actix-web.
WARNING
This library is currently in early access and may recieve breaking changes.
Supported Validation Libraries
Usage
Any type that implments the Actix FromRequest
trait can be automatically validated.
# Cargo.toml
= { = "0.0.0", = ["validator"]}
# or
= { = "0.0.0", = ["garde"]}
use Validated;
use Validate;
// or for garde
// use actix_web_validation::garde::Validated;
// use garde::Validate;
// Do validation using your validation library
// Wrap your Actix extractor with `Validated` to automatically run validation
async : )
Custom Errors
Custom error responses can achieved by providing an error handler.
Below is an example custom error response that responds with JSON
// impl Display for CustomErrorResponse { ... }
Below is an example for the validator
crate
async
Below is an example for the garde
crate
async
Motivations
This library is heavily inspired by Spring Validation and actix-web-validator.
The actix-web-validator is great but there are a few pain points I would like to address with this library.
- More explict validation by using the
Validated
extractor to reduce the risk of using the wrongJson
/Query
/ect extractor by mistake. - Provide a common interface for validation libraries that can be extended as the Rust ecosystem evolves.