Adding optional query get parameter to route #1259
-
Hello, First of all, thanks for this really awesome framework. I honestly did not expect to have so much fun again writing a web app! I am a bit stuck right now. I want to add an optional query get parameter to a route and pass it on to the view.
I would have expected that the AppContext would have this information, but I can't find anything right now. Can someone help me to solve this? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
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
...
} |
Beta Was this translation helpful? Give feedback.
I don't see the query parameters struct in your controller. You can follow on this example: