How do you route queries in the rust library Warp?

I spent my whole day trying to route /search?query=Google.

    let search = warp::path("search")
        .and(warp::query::<String>())
        .map(|query: String| {
            warp::reply::html(format!("<p>{query}</p>"))
        });

This however, results in a "Invalid query string", when I go http://localhost:3030/search?query=asgf.
This has to be the worst error message I ever received.

You need to use a type that deserializes from key value pairs with the query filter. String deserializes as a single value, which doesn't work with the filter.

The examples show using a HashMap to get dynamic query values and a custom struct using the serde derive macros to get known query values.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.