Skip to content

Commit fc85f20

Browse files
committed
add querystring example #291
Signed-off-by: Yoshua Wuyts <[email protected]>
1 parent e226414 commit fc85f20

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

src/querystring.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,21 @@ use http::StatusCode;
33
use serde::Deserialize;
44

55
/// An extension trait for `Context`, providing query string deserialization.
6+
///
7+
/// # Example
8+
///
9+
/// Turning the query parameters into a `HashMap`:
10+
///
11+
/// ```
12+
/// # use std::collections::HashMap;
13+
/// use tide::querystring::ContextExt;
14+
///
15+
/// let mut app = tide::App::new();
16+
/// app.at("/").get(|cx: tide::Context<()>| async move {
17+
/// let map: HashMap<String, String> = cx.url_query().unwrap();
18+
/// format!("{:?}", map)
19+
/// });
20+
/// ```
621
pub trait ContextExt<'de> {
722
fn url_query<T: Deserialize<'de>>(&'de self) -> Result<T, Error>;
823
}

0 commit comments

Comments
 (0)