Struct Query

struct Query<T>(2442)

Extractor that deserializes query strings into some type.

T is expected to implement serde::Deserialize.

Examples

use axum::{
    extract::Query,
    routing::get,
    Router,
};
use serde::Deserialize;

#[derive(Deserialize)]
struct Pagination {
    page: usize,
    per_page: usize,
}

// This will parse query strings like `?page=2&per_page=30` into `Pagination`
// structs.
async fn list_things(pagination: Query<Pagination>) {
    let pagination: Pagination = pagination.0;

    // ...
}

let app = Router::new().route("/list_things", get(list_things));
# let _: Router = app;

If the query string cannot be parsed it will reject the request with a 400 Bad Request response.

For handling values being empty vs missing see the query-params-with-empty-strings example.

For handling multiple values for the same query parameter, in a ?foo=1&foo=2&foo=3 fashion, use axum_extra::extract::Query instead.

Implementations

impl<T> Query<T>

fn try_from_uri(value: &Uri) -> Result<Self, QueryRejection>

Attempts to construct a Query from a reference to a Uri.

Example

use axum::extract::Query;
use http::Uri;
use serde::Deserialize;

#[derive(Deserialize)]
struct ExampleParams {
    foo: String,
    bar: u32,
}

let uri: Uri = "http://example.com/path?foo=hello&bar=42".parse().unwrap();
let result: Query<ExampleParams> = Query::try_from_uri(&uri).unwrap();
assert_eq!(result.foo, String::from("hello"));
assert_eq!(result.bar, 42);

impl<P, T> Receiver for Query<T>

impl<R> Rng for Query<T>

impl<R> TryCryptoRng for Query<T>

impl<R> TryRngCore for Query<T>

fn try_next_u32(self: &mut Self) -> Result<u32, <R as TryRngCore>::Error>
fn try_next_u64(self: &mut Self) -> Result<u64, <R as TryRngCore>::Error>
fn try_fill_bytes(self: &mut Self, dst: &mut [u8]) -> Result<(), <R as TryRngCore>::Error>

impl<S, T> FromRequest for Query<T>

fn from_request(req: Request<Body>, state: &S) -> impl Future<Output = Result<T, <T as FromRequest<S, ViaParts>>::Rejection>>

impl<T> Any for Query<T>

fn type_id(self: &Self) -> TypeId

impl<T> Borrow for Query<T>

fn borrow(self: &Self) -> &T

impl<T> BorrowMut for Query<T>

fn borrow_mut(self: &mut Self) -> &mut T

impl<T> CloneToUninit for Query<T>

unsafe fn clone_to_uninit(self: &Self, dest: *mut u8)

impl<T> CryptoRng for Query<T>

impl<T> Deref for Query<T>

fn deref(self: &Self) -> &<Self as >::Target

impl<T> DerefMut for Query<T>

fn deref_mut(self: &mut Self) -> &mut <Self as >::Target

impl<T> Freeze for Query<T>

impl<T> From for Query<T>

fn from(t: T) -> T

Returns the argument unchanged.

impl<T> FromRef for Query<T>

fn from_ref(input: &T) -> T

impl<T> Instrument for Query<T>

impl<T> RefUnwindSafe for Query<T>

impl<T> RngCore for Query<T>

fn next_u32(self: &mut Self) -> u32
fn next_u64(self: &mut Self) -> u64
fn fill_bytes(self: &mut Self, dst: &mut [u8])

impl<T> Same for Query<T>

impl<T> Send for Query<T>

impl<T> Sync for Query<T>

impl<T> ToOwned for Query<T>

fn to_owned(self: &Self) -> T
fn clone_into(self: &Self, target: &mut T)

impl<T> Unpin for Query<T>

impl<T> UnsafeUnpin for Query<T>

impl<T> UnwindSafe for Query<T>

impl<T> WithSubscriber for Query<T>

impl<T, S> FromRequestParts for Query<T>

async fn from_request_parts(parts: &mut Parts, _state: &S) -> Result<Self, <Self as >::Rejection>

impl<T, U> Into for Query<T>

fn into(self: Self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of [From]<T> for U chooses to do.

impl<T, U> TryFrom for Query<T>

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

impl<T, U> TryInto for Query<T>

fn try_into(self: Self) -> Result<U, <U as TryFrom<T>>::Error>

impl<T: $crate::clone::Clone> Clone for Query<T>

fn clone(self: &Self) -> Query<T>

impl<T: $crate::default::Default> Default for Query<T>

fn default() -> Query<T>

impl<T: $crate::fmt::Debug> Debug for Query<T>

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

impl<T: $crate::marker::Copy> Copy for Query<T>

impl<V, T> VZip for Query<T>

fn vzip(self: Self) -> V