pub struct TestRequestBuilder<S> { /* private fields */ }Expand description
A request builder produced by TestClient.
Accumulates method, path, headers, and body, then executes the request
via send.
§Examples
use volter_testing::TestClient;
use volter_router::{Router, get};
async fn handler() -> &'static str { "ok" }
let client = TestClient::new(Router::new().route("/", get(handler)));
let response = client.get("/").send().await;
assert_eq!(response.status(), 200);Implementations§
Source§impl<S: Clone + Send + 'static> TestRequestBuilder<S>
impl<S: Clone + Send + 'static> TestRequestBuilder<S>
Sourcepub fn header(self, name: HeaderName, value: HeaderValue) -> Self
pub fn header(self, name: HeaderName, value: HeaderValue) -> Self
Add a header to the request.
Existing headers with the same name are not removed — the value is appended.
Sourcepub fn json<T: Serialize>(self, value: &T) -> Self
pub fn json<T: Serialize>(self, value: &T) -> Self
Set the request body to a JSON-serialized value.
Also sets the Content-Type header to application/json.
Sourcepub async fn send(self) -> TestResponse
pub async fn send(self) -> TestResponse
Build the http::Request, dispatch it through the cloned router, and
return a TestResponse.
Auto Trait Implementations§
impl<S> !Freeze for TestRequestBuilder<S>
impl<S> !RefUnwindSafe for TestRequestBuilder<S>
impl<S> !Sync for TestRequestBuilder<S>
impl<S> !UnwindSafe for TestRequestBuilder<S>
impl<S> Send for TestRequestBuilder<S>where
S: Send,
impl<S> Unpin for TestRequestBuilder<S>where
S: Unpin,
impl<S> UnsafeUnpin for TestRequestBuilder<S>where
S: UnsafeUnpin,
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