Skip to content

Extract named query parameter #147

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

Closed
niklasf opened this issue Mar 7, 2019 · 3 comments
Closed

Extract named query parameter #147

niklasf opened this issue Mar 7, 2019 · 3 comments
Labels
feature A feature that's ready for implementation

Comments

@niklasf
Copy link

niklasf commented Mar 7, 2019

Feature Request

Extract named parameters from query strings (?param1=foo&param2=bar).

Detailed Description

tide supports query extraction (#14) using UrlQuery. For example:

async fn hello_world(UrlQuery(q): UrlQuery<String>) -> String {
    q // "param1=foo&param2=bar" (how to extract the value of param1?)
}

UrlQuery<T> parses T using FromStr, but if we want to parse the query and extract individual parameters we're on our own.

Context

Working with query parameters is common in all kinds of applications.

Possible Implementation

Looking at tide itself, it could be implemented similarly to named segments. Alternatives from other frameworks:

  • Rocket: Derivable FromForm trait. Function parameter is marked as query string in route declaration.
    #[get("/hello?<q>")]
    fn hello_world(q: &MyTypeThatImplsFromForm) -> /* ... */
  • actix-web: Parameter Query<T: Deserialize> newtype using serde_urlencoded.
  • tower-web: Derivable Extract trait. Function parameter must be named query_string.
#[get("/query-string")]
fn hello_world(&self, query_string: Option<Foo>) -> /* ... */

The actix-web approach might be best for Tide, because no macro magic is involved. (Well ... except that in Serde).

@yoshuawuyts
Copy link
Member

Related: #108

@aturon aturon added the feature A feature that's ready for implementation label Apr 10, 2019
@aturon
Copy link
Collaborator

aturon commented Apr 10, 2019

This should be easier to explore now that #156 has landed!

@secretfader
Copy link

secretfader commented Apr 18, 2019

#175 addresses this feature.

secretfader pushed a commit to secretfader/tide that referenced this issue Apr 23, 2019
Resolve http-rs#147 by adding query string extraction and validation via the `ExtractQuery` trait,
implemented for `tide::Context`.
secretfader pushed a commit to secretfader/tide that referenced this issue Apr 23, 2019
Resolve http-rs#147 by adding query string extraction and validation via the `ExtractQuery` trait, implemented for `tide::Context`.
@aturon aturon closed this as completed in 85065cf Apr 24, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature A feature that's ready for implementation
Projects
None yet
Development

No branches or pull requests

4 participants