FromRequest

Derive Macro FromRequest 

Source
#[derive(FromRequest)]
{
    // Attributes available to this derive:
    #[from_request]
}
Available on crate feature derive only.
Expand description

Derive a FromRequest implementation for an aggregate struct extractor.

All fields of the struct need to implement FromRequest unless they are marked with annotations that declare different handling is required.

ยงExamples

use actix_web::{Responder, get, http, web};
use actix_web_lab::FromRequest;

#[derive(Debug, FromRequest)]
struct RequestParts {
    // the FromRequest impl is used for these fields
    method: http::Method,
    pool: web::Data<u32>,
    req_body: String,

    // equivalent to `req.app_data::<u64>().copied()`
    #[from_request(copy_from_app_data)]
    int: u64,
}

#[get("/")]
async fn handler(parts: RequestParts) -> impl Responder {
    // ...
}