It looks like they removed the query function and just have a query_string function. You could use a crate for this called qstring:
use qstring::QString;
...
let query_str = req.query_string(); // "name=ferret"
let qs = QString::from(query_str);
let name = qs.get("name").unwrap(); // "ferret"
You could also use an extractor to deserialize the query params into a struct with Serde
use serde::Deserialize;
#[derive(Deserialize)]
struct Info {
username: String,
}
fn index(info: web::Query<Info>) -> Result<String, actix_web::Error> {
Ok(format!("Welcome {}!", info.username))
}
Note that the handler will only be called if the query username is actually present in the request. This would call the handler:
curl "http://localhost:5000?username=joe"
but these would not:
curl "http://localhost:5000"
curl "http://localhost:5000?password=blah"
If you need optional parameters, just make the properties in your struct Options.
username: Option<String>
You can also use multiple web::Query<SomeType> parameters in a handler.