Skip to content

Extract seperate Path parameters in middleware and handler #3249

Answered by jplatte
adamsdally asked this question in Q&A
Discussion options

You must be logged in to vote

You can do it like this:

use serde::Deserialize;

#[derive(Deserialize)]
struct MiddlewarePath {
    account_id: i64,
}

#[derive(Deserialize)]
struct HandlerPath {
    invite_id: i64,
}

pub async fn account_admin(
    Path(MiddlewarePath { account_id }): Path<MiddlewarePath>,
    State(pool): State<Pool<Sqlite>>,
    req: Request,
    next: Next,
) -> Result<Response, StatusCode> {
    // ...
}

pub async fn remove_invite(
    Path(HandlerPath { invite_id }): Path<HandlerPath>,
    State(pool): State<Pool<Sqlite>>,
) -> StatusCode {
    // ...
}

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
1 reply
@adamsdally
Comment options

Comment options

You must be logged in to vote
1 reply
@adamsdally
Comment options

Answer selected by adamsdally
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants