Could anyone please give me a simple query string deserialization example? I'm was messing around for two hour but still can't find the way.
Nevermind. I found it.
@nhphu maybe post the example code for people having the same issue 馃槈?
use serde_derive::Deserialize;
use warp::Filter;
fn main() {
// GET /area?width=25&height=5 => "Area = 125"
let area = warp::get2().and(warp::path("area"))
.and(warp::query().map(|r: Rectangle| format!("Area = {}", r.width * r.height)));
warp::serve(area).run(([0, 0, 0, 0], 3030));
}
#[derive(Deserialize)]
struct Rectangle {
width: u32,
height: u32,
}
I was searching for this example for an hour now. I'm glad I found it. Thanks!
Is it possible to add this to the examples directory and/or the documentation on queries?
Can someone provide an example of a filter which combines a parameter _and_ a query string?
And here I am answering my own question as well:
warp::path("rectangle")
.and(warp::path::param())
.and(warp::path::end())
.and(warp::query::<Rectangle>())
.map(move |measure: String, r: Rectangle| {
format!("Measure = {}, Width = {}, Height = {}", measure, r.width, r.height)
});
I also searched for an hour before arriving here. Adding an example would be good I think.
if anyone wants to submit a PR with it :+1:
I submitted a PR.
Most helpful comment