pub struct QueryString<T>(pub T);
Expand description
Axum’s Query extractor, modified to use serde-querystring.
T
is expected to implement serde::Deserialize
.
§Example
use axum::{
routing::get,
Router,
};
use serde::Deserialize;
use serde_querystring_axum::QueryString;
#[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: QueryString<Pagination>) {
let pagination: Pagination = pagination.0;
// ...
}
let app = Router::new().route("/list_things", get(list_things));
If the query string cannot be parsed it will reject the request with a 422 Unprocessable Entity
response.
To change the default error and the parsing mode, add QueryStringConfig
to your extensions.
use axum::{Router, Extension, http::StatusCode};
use serde_querystring_axum::{ParseMode, QueryStringConfig};
let app = Router::new().layer(Extension(
QueryStringConfig::new(ParseMode::Brackets).ehandler(|err| {
(StatusCode::BAD_REQUEST, err.to_string()) // return type should impl IntoResponse
}),
));
Tuple Fields§
§0: T
Trait Implementations§
Source§impl<T: Clone> Clone for QueryString<T>
impl<T: Clone> Clone for QueryString<T>
Source§fn clone(&self) -> QueryString<T>
fn clone(&self) -> QueryString<T>
Returns a copy of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreSource§impl<T: Debug> Debug for QueryString<T>
impl<T: Debug> Debug for QueryString<T>
Source§impl<T: Default> Default for QueryString<T>
impl<T: Default> Default for QueryString<T>
Source§fn default() -> QueryString<T>
fn default() -> QueryString<T>
Returns the “default value” for a type. Read more
Source§impl<T> Deref for QueryString<T>
impl<T> Deref for QueryString<T>
Source§impl<T, S> FromRequestParts<S> for QueryString<T>
impl<T, S> FromRequestParts<S> for QueryString<T>
impl<T: Copy> Copy for QueryString<T>
Auto Trait Implementations§
impl<T> Freeze for QueryString<T>where
T: Freeze,
impl<T> RefUnwindSafe for QueryString<T>where
T: RefUnwindSafe,
impl<T> Send for QueryString<T>where
T: Send,
impl<T> Sync for QueryString<T>where
T: Sync,
impl<T> Unpin for QueryString<T>where
T: Unpin,
impl<T> UnwindSafe for QueryString<T>where
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<S, B, T> FromRequest<S, B, ViaParts> for T
impl<S, B, T> FromRequest<S, B, ViaParts> for T
Source§type Rejection = <T as FromRequestParts<S>>::Rejection
type Rejection = <T as FromRequestParts<S>>::Rejection
If the extractor fails it’ll use this “rejection” type. A rejection is
a kind of error that can be converted into a response.