Struct poem::test::TestRequestBuilder
source · [−]pub struct TestRequestBuilder<'a, E> { /* private fields */ }
This is supported on crate feature
test
only.Expand description
A request builder for testing.
Implementations
sourceimpl<'a, E> TestRequestBuilder<'a, E> where
E: Endpoint,
impl<'a, E> TestRequestBuilder<'a, E> where
E: Endpoint,
sourcepub fn query(self, name: impl Into<String>, value: &impl Serialize) -> Self
pub fn query(self, name: impl Into<String>, value: &impl Serialize) -> Self
Sets the query string for this request.
Example
use poem::{handler, test::TestClient, web::Query, Route};
use serde::Deserialize;
#[derive(Deserialize)]
struct Params {
key: String,
value: i32,
}
#[handler]
fn index(Query(params): Query<Params>) -> String {
format!("{}={}", params.key, params.value)
}
let app = Route::new().at("/", index);
let cli = TestClient::new(app);
let resp = cli
.get("/")
.query("key", &"a")
.query("value", &10)
.send()
.await;
resp.assert_status_is_ok();
resp.assert_text("a=10").await;
sourcepub fn header<K, V>(self, key: K, value: V) -> Self where
K: TryInto<HeaderName>,
V: TryInto<HeaderValue>,
pub fn header<K, V>(self, key: K, value: V) -> Self where
K: TryInto<HeaderName>,
V: TryInto<HeaderValue>,
Sets the header value for this request.
sourcepub fn typed_header<T: Header>(self, header: T) -> Self
pub fn typed_header<T: Header>(self, header: T) -> Self
Inserts a typed header to this request.
sourcepub fn content_type(self, content_type: impl AsRef<str>) -> Self
pub fn content_type(self, content_type: impl AsRef<str>) -> Self
Sets the content type for this request.
sourcepub fn body_json(self, body: &impl Serialize) -> Self
pub fn body_json(self, body: &impl Serialize) -> Self
Sets the JSON body for this request with application/json
content
type.
sourcepub fn form(self, form: &impl Serialize) -> Self
pub fn form(self, form: &impl Serialize) -> Self
Sets the form data for this request with
application/x-www-form-urlencoded
content type.
sourcepub fn multipart(self, form: TestForm) -> Self
pub fn multipart(self, form: TestForm) -> Self
Sets the multipart body for this request with multipart/form-data
content type.
sourcepub fn data<T>(self, data: T) -> Self where
T: Send + Sync + 'static,
pub fn data<T>(self, data: T) -> Self where
T: Send + Sync + 'static,
Sets the extension data for this request.
Example
use poem::{handler, test::TestClient, web::Data, Route};
#[handler]
fn index(Data(value): Data<&i32>) -> String {
value.to_string()
}
let app = Route::new().at("/", index);
let cli = TestClient::new(app);
let resp = cli.get("/").data(100i32).send().await;
resp.assert_status_is_ok();
resp.assert_text("100").await;
sourcepub async fn send(self) -> TestResponse
pub async fn send(self) -> TestResponse
Send this request to endpoint to get the response.
Auto Trait Implementations
impl<'a, E> !RefUnwindSafe for TestRequestBuilder<'a, E>
impl<'a, E> Send for TestRequestBuilder<'a, E> where
E: Sync,
impl<'a, E> Sync for TestRequestBuilder<'a, E> where
E: Sync,
impl<'a, E> Unpin for TestRequestBuilder<'a, E>
impl<'a, E> !UnwindSafe for TestRequestBuilder<'a, E>
Blanket Implementations
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
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>
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