Struct ntex::web::types::Query [−][src]
pub struct Query<T>(pub T);
Expand description
Extract typed information from the request’s query.
Note: A query string consists of unordered key=value
pairs, therefore it cannot
be decoded into any type which depends upon data ordering e.g. tuples or tuple-structs.
Attempts to do so will fail at runtime.
QueryConfig allows to configure extraction process.
Example
use ntex::web; #[derive(Debug, serde::Deserialize)] pub enum ResponseType { Token, Code } #[derive(serde::Deserialize)] pub struct AuthRequest { id: u64, response_type: ResponseType, } // Use `Query` extractor for query information (and destructure it within the signature). // This handler gets called only if the request's query string contains a `username` field. // The correct request for this handler would be `/index.html?id=64&response_type=Code"`. async fn index(web::types::Query(info): web::types::Query<AuthRequest>) -> String { format!("Authorization request for client with id={} and type={:?}!", info.id, info.response_type) } fn main() { let app = web::App::new().service( web::resource("/index.html").route(web::get().to(index))); // <- use `Query` extractor }
Implementations
impl<T> Query<T>
[src]
impl<T> Query<T>
[src]pub fn into_inner(self) -> T
[src]
pub fn into_inner(self) -> T
[src]Deconstruct to a inner value
pub fn from_query(query_str: &str) -> Result<Self, QueryPayloadError> where
T: DeserializeOwned,
[src]
pub fn from_query(query_str: &str) -> Result<Self, QueryPayloadError> where
T: DeserializeOwned,
[src]Get query parameters from the path
Trait Implementations
impl<T, Err> FromRequest<Err> for Query<T> where
T: DeserializeOwned,
Err: ErrorRenderer,
[src]
impl<T, Err> FromRequest<Err> for Query<T> where
T: DeserializeOwned,
Err: ErrorRenderer,
[src]Extract typed information from the request’s query.
Example
use ntex::web; #[derive(Debug, serde::Deserialize)] pub enum ResponseType { Token, Code } #[derive(serde::Deserialize)] pub struct AuthRequest { id: u64, response_type: ResponseType, } // Use `Query` extractor for query information. // This handler get called only if request's query contains `username` field // The correct request for this handler would be `/index.html?id=64&response_type=Code"` async fn index(info: web::types::Query<AuthRequest>) -> String { format!("Authorization request for client with id={} and type={:?}!", info.id, info.response_type) } fn main() { let app = web::App::new().service( web::resource("/index.html") .route(web::get().to(index))); // <- use `Query` extractor }
type Error = QueryPayloadError
type Error = QueryPayloadError
The associated error which can be returned.
fn from_request(req: &HttpRequest, _: &mut Payload) -> Self::Future
[src]
fn from_request(req: &HttpRequest, _: &mut Payload) -> Self::Future
[src]Convert request to a Self
fn extract(req: &HttpRequest) -> Self::Future
[src]
fn extract(req: &HttpRequest) -> Self::Future
[src]Convert request to a Self Read more
impl<T: Ord> Ord for Query<T>
[src]
impl<T: Ord> Ord for Query<T>
[src]impl<T: PartialOrd> PartialOrd<Query<T>> for Query<T>
[src]
impl<T: PartialOrd> PartialOrd<Query<T>> for Query<T>
[src]fn partial_cmp(&self, other: &Query<T>) -> Option<Ordering>
[src]
fn partial_cmp(&self, other: &Query<T>) -> Option<Ordering>
[src]This method returns an ordering between self
and other
values if one exists. Read more
#[must_use]fn lt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]fn lt(&self, other: &Rhs) -> bool
1.0.0[src]This method tests less than (for self
and other
) and is used by the <
operator. Read more
#[must_use]fn le(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]fn le(&self, other: &Rhs) -> bool
1.0.0[src]This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
impl<T: Eq> Eq for Query<T>
[src]
impl<T> StructuralEq for Query<T>
[src]
impl<T> StructuralPartialEq for Query<T>
[src]
Auto Trait Implementations
impl<T> RefUnwindSafe for Query<T> where
T: RefUnwindSafe,
T: RefUnwindSafe,
impl<T> Send for Query<T> where
T: Send,
T: Send,
impl<T> Sync for Query<T> where
T: Sync,
T: Sync,
impl<T> Unpin for Query<T> where
T: Unpin,
T: Unpin,
impl<T> UnwindSafe for Query<T> where
T: UnwindSafe,
T: UnwindSafe,
Blanket Implementations
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]pub fn borrow_mut(&mut self) -> &mut T
[src]
pub fn borrow_mut(&mut self) -> &mut T
[src]Mutably borrows from an owned value. Read more
impl<Q, K> Equivalent<K> for Q where
K: Borrow<Q> + ?Sized,
Q: Eq + ?Sized,
[src]
impl<Q, K> Equivalent<K> for Q where
K: Borrow<Q> + ?Sized,
Q: Eq + ?Sized,
[src]pub fn equivalent(&self, key: &K) -> bool
[src]
pub fn equivalent(&self, key: &K) -> bool
[src]Compare self to key
and return true
if they are equal.
impl<T> Instrument for T
[src]
impl<T> Instrument for T
[src]fn instrument(self, span: Span) -> Instrumented<Self>
[src]
fn instrument(self, span: Span) -> Instrumented<Self>
[src]Instruments this type with the provided Span
, returning an
Instrumented
wrapper. Read more
fn in_current_span(self) -> Instrumented<Self>
[src]
fn in_current_span(self) -> Instrumented<Self>
[src]impl<T> Same<T> for T
impl<T> Same<T> for T
type Output = T
type Output = T
Should always be Self