Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add doc example showing query parameter extraction #291

Merged
merged 1 commit into from Jul 18, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -14,6 +14,23 @@ use serde::Deserialize;
use tide_core::{error::Error, Context};

/// An extension trait for `Context`, providing query string deserialization.
///
/// # Example
///
/// Turning the query parameters into a `HashMap`:
///
/// ```
/// #![feature(async_await)]
///
/// # use std::collections::HashMap;
/// use tide::querystring::ContextExt;
///
/// let mut app = tide::App::new();
/// app.at("/").get(|cx: tide::Context<()>| async move {
/// let map: HashMap<String, String> = cx.url_query().unwrap();
/// format!("{:?}", map)
/// });
/// ```
pub trait ContextExt<'de> {
/// Analyze url and extract query parameters
fn url_query<T: Deserialize<'de>>(&'de self) -> Result<T, Error>;