Dependency injection? #3270
-
Hello, #[get("/user/{user_id}")]
pub async fn get_one(user: User) -> impl Responder {
// Some more operations
retrun HttpResponse::Ok().json(user);
} The things is that user needs to have access to the user_id and the identity (from actixcidentity crate). Is there any way to make this work? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Edit: |
Beta Was this translation helpful? Give feedback.
The FromRequest trait support async operations, see docs: https://docs.rs/actix-web/latest/actix_web/trait.FromRequest.html#associatedtype.Future
I'd suggest that creating an extractor (impl FromRequest) is the right way of achieving your goal here.