Struct salvo_core::test::RequestBuilder
source · pub struct RequestBuilder { /* private fields */ }
test
only.Expand description
RequestBuilder
is the main way of building requests.
You can create a RequestBuilder
using the new
or try_new
method, but the recommended way
or use one of the simpler constructors available in the crate root or on the Session
struct,
such as get
, post
, etc.
Implementations§
source§impl RequestBuilder
impl RequestBuilder
sourcepub fn query<K, V>(self, key: K, value: V) -> Selfwhere
K: AsRef<str>,
V: ToString,
pub fn query<K, V>(self, key: K, value: V) -> Selfwhere
K: AsRef<str>,
V: ToString,
Associate a query string parameter to the given value.
The same key can be used multiple times.
sourcepub fn queries<P, K, V>(self, pairs: P) -> Selfwhere
P: IntoIterator,
P::Item: Borrow<(K, V)>,
K: AsRef<str>,
V: ToString,
pub fn queries<P, K, V>(self, pairs: P) -> Selfwhere
P: IntoIterator,
P::Item: Borrow<(K, V)>,
K: AsRef<str>,
V: ToString,
Associated a list of pairs to query parameters.
The same key can be used multiple times.
Example
TestClient::get("http://foo.bar").queries(&[("p1", "v1"), ("p2", "v2")]);
sourcepub fn basic_auth(
self,
username: impl Display,
password: Option<impl Display>
) -> Self
pub fn basic_auth(
self,
username: impl Display,
password: Option<impl Display>
) -> Self
Enable HTTP basic authentication.
sourcepub fn bearer_auth(self, token: impl Into<String>) -> Self
pub fn bearer_auth(self, token: impl Into<String>) -> Self
Enable HTTP bearer authentication.
sourcepub fn text(self, body: impl Into<String>) -> Self
pub fn text(self, body: impl Into<String>) -> Self
Sets the body of this request to be text.
If the Content-Type
header is unset, it will be set to text/plain
and the charset to UTF-8.
sourcepub fn bytes(self, body: Vec<u8>) -> Self
pub fn bytes(self, body: Vec<u8>) -> Self
Sets the body of this request to be bytes.
If the Content-Type
header is unset, it will be set to application/octet-stream
.
sourcepub fn json<T: Serialize>(self, value: &T) -> Self
pub fn json<T: Serialize>(self, value: &T) -> Self
Sets the body of this request to be the JSON representation of the given object.
If the Content-Type
header is unset, it will be set to application/json
and the charset to UTF-8.
sourcepub fn raw_json(self, value: impl Into<String>) -> Self
pub fn raw_json(self, value: impl Into<String>) -> Self
Sets the body of this request to be the JSON representation of the given string.
If the Content-Type
header is unset, it will be set to application/json
and the charset to UTF-8.
sourcepub fn form<T: Serialize>(self, value: &T) -> Self
pub fn form<T: Serialize>(self, value: &T) -> Self
Sets the body of this request to be the URL-encoded representation of the given object.
If the Content-Type
header is unset, it will be set to application/x-www-form-urlencoded
.
sourcepub fn raw_form(self, value: impl Into<String>) -> Self
pub fn raw_form(self, value: impl Into<String>) -> Self
Sets the body of this request to be the URL-encoded representation of the given string.
If the Content-Type
header is unset, it will be set to application/x-www-form-urlencoded
.
sourcepub fn add_header<N, V>(self, name: N, value: V, overwrite: bool) -> Selfwhere
N: IntoHeaderName,
V: TryInto<HeaderValue>,
pub fn add_header<N, V>(self, name: N, value: V, overwrite: bool) -> Selfwhere
N: IntoHeaderName,
V: TryInto<HeaderValue>,
Modify a header for this response.
When overwrite
is set to true
, If the header is already present, the value will be replaced.
When overwrite
is set to false
, The new header is always appended to the request, even if the header already exists.
sourcepub fn build_hyper(self) -> Request<Body>
pub fn build_hyper(self) -> Request<Body>
Build hyper request.