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]

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]

Get query parameters from the path

Trait Implementations

impl<T: Debug> Debug for Query<T>[src]

fn fmt(&self, f: &mut Formatter<'_>) -> Result[src]

Formats the value using the given formatter. Read more

impl<T> Deref for Query<T>[src]

type Target = T

The resulting type after dereferencing.

fn deref(&self) -> &T[src]

Dereferences the value.

impl<T> DerefMut for Query<T>[src]

fn deref_mut(&mut self) -> &mut T[src]

Mutably dereferences the value.

impl<T: Display> Display for Query<T>[src]

fn fmt(&self, f: &mut Formatter<'_>) -> Result[src]

Formats the value using the given formatter. Read more

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

The associated error which can be returned.

type Future = Ready<Self, Self::Error>

Future that resolves to a Self

fn from_request(req: &HttpRequest, _: &mut Payload) -> Self::Future[src]

Convert request to a Self

fn extract(req: &HttpRequest) -> Self::Future[src]

Convert request to a Self Read more

impl<T: Ord> Ord for Query<T>[src]

fn cmp(&self, other: &Query<T>) -> Ordering[src]

This method returns an Ordering between self and other. Read more

#[must_use]
fn max(self, other: Self) -> Self
1.21.0[src]

Compares and returns the maximum of two values. Read more

#[must_use]
fn min(self, other: Self) -> Self
1.21.0[src]

Compares and returns the minimum of two values. Read more

#[must_use]
fn clamp(self, min: Self, max: Self) -> Self
1.50.0[src]

Restrict a value to a certain interval. Read more

impl<T: PartialEq> PartialEq<Query<T>> for Query<T>[src]

fn eq(&self, other: &Query<T>) -> bool[src]

This method tests for self and other values to be equal, and is used by ==. Read more

fn ne(&self, other: &Query<T>) -> bool[src]

This method tests for !=.

impl<T: PartialOrd> PartialOrd<Query<T>> for Query<T>[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]

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]

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

#[must_use]
fn gt(&self, other: &Rhs) -> bool
1.0.0[src]

This method tests greater than (for self and other) and is used by the > operator. Read more

#[must_use]
fn ge(&self, other: &Rhs) -> bool
1.0.0[src]

This method tests greater 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

impl<T> Send for Query<T> where
    T: Send

impl<T> Sync for Query<T> where
    T: Sync

impl<T> Unpin for Query<T> where
    T: Unpin

impl<T> UnwindSafe for Query<T> where
    T: UnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

pub fn type_id(&self) -> TypeId[src]

Gets the TypeId of self. Read more

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

pub fn borrow(&self) -> &T[src]

Immutably borrows from an owned value. Read more

impl<T> BorrowMut<T> for T where
    T: ?Sized
[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]

pub fn equivalent(&self, key: &K) -> bool[src]

Compare self to key and return true if they are equal.

impl<T> From<T> for T[src]

pub fn from(t: T) -> T[src]

Performs the conversion.

impl<T> Instrument for T[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]

Instruments this type with the current Span, returning an Instrumented wrapper. Read more

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

pub fn into(self) -> U[src]

Performs the conversion.

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<T> ToString for T where
    T: Display + ?Sized
[src]

pub default fn to_string(&self) -> String[src]

Converts the given value to a String. Read more

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src]

Performs the conversion.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>[src]

Performs the conversion.