pub struct Query<T>(pub T);
Expand description
An extractor that can deserialize some type from query string.
Errors
Example
use poem::{
get, handler,
http::{Method, StatusCode, Uri},
test::TestClient,
web::Query,
Endpoint, Request, Route,
};
use serde::Deserialize;
#[derive(Deserialize)]
struct CreateDocument {
title: String,
content: String,
}
#[handler]
fn index(Query(CreateDocument { title, content }): Query<CreateDocument>) -> String {
format!("{}:{}", title, content)
}
let app = Route::new().at("/", get(index).post(index));
let cli = TestClient::new(app);
let resp = cli
.get("/")
.query("title", &"foo")
.query("content", &"bar")
.send()
.await;
resp.assert_status_is_ok();
resp.assert_text("foo:bar").await;
Tuple Fields
0: T
Trait Implementations
sourceimpl<'a, T: DeserializeOwned> FromRequest<'a> for Query<T>
impl<'a, T: DeserializeOwned> FromRequest<'a> for Query<T>
sourcefn from_request<'life0, 'async_trait>(
req: &'a Request,
_body: &'life0 mut RequestBody
) -> Pin<Box<dyn Future<Output = Result<Self>> + Send + 'async_trait>> where
'a: 'async_trait,
'life0: 'async_trait,
Self: 'async_trait,
fn from_request<'life0, 'async_trait>(
req: &'a Request,
_body: &'life0 mut RequestBody
) -> Pin<Box<dyn Future<Output = Result<Self>> + Send + 'async_trait>> where
'a: 'async_trait,
'life0: 'async_trait,
Self: 'async_trait,
Extract from request head and body.
impl<T: Eq> Eq for Query<T>
impl<T> StructuralEq for Query<T>
impl<T> StructuralPartialEq for Query<T>
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, A, P> Access<T> for P where
A: Access<T>,
P: Deref<Target = A>,
impl<T, A, P> Access<T> for P where
A: Access<T>,
P: Deref<Target = A>,
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<T, A> DynAccess<T> for A where
A: Access<T>,
<A as Access<T>>::Guard: 'static,
impl<T, A> DynAccess<T> for A where
A: Access<T>,
<A as Access<T>>::Guard: 'static,
fn load(&self) -> DynGuard<T>
fn load(&self) -> DynGuard<T>
The equivalent of [Access::load
].
sourceimpl<Q, K> Equivalent<K> for Q where
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Q where
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
sourcefn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to key
and return true
if they are equal.
sourceimpl<T> FutureExt for T
impl<T> FutureExt for T
sourcefn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
sourcefn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
🔬 This is a nightly-only experimental API. (
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
fn vzip(self) -> V
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
sourcefn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more