Skip to content

Adding optional query get parameter to route #1259

Answered by kaplanelad
kmerz asked this question in Q&A
Discussion options

You must be logged in to vote

I don't see the query parameters struct in your controller. You can follow on this example:

use axum::extract::Query;

#[derive(Deserialize, Debug)]
pub struct ExampleQueryParams {
    pub trip_id: Option<String>,
}

#[debug_handler]
pub async fn test_endpoint(
    ViewEngine(v): ViewEngine<TeraView>,
    State(ctx): State<AppContext>,
    Query(params): Query<ExampleQueryParams>,
) -> Result<Response> {

   let trip_id = params.trip_id
  ...
}

Replies: 1 comment 1 reply

Comment options

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

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