#[request]Expand description
Attribute macro for clean request data definition
This is the recommended way to define validated request types. It automatically adds the necessary derives and generates the trait impl.
Works with both:
application/json- JSON request bodiesapplication/x-www-form-urlencoded- HTML form submissions
§Example
ⓘ
use ferro::request;
#[request]
pub struct CreateUserRequest {
#[validate(email)]
pub email: String,
#[validate(length(min = 8))]
pub password: String,
}
// This can now be used directly in handlers:
#[handler]
pub async fn store(form: CreateUserRequest) -> Response {
// Automatically validated - returns 422 with errors if invalid
json_response!({ "email": form.email })
}