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
sourceimpl RequestBuilder
impl RequestBuilder
sourceimpl RequestBuilder
impl RequestBuilder
sourcepub fn query<K, V>(self, key: K, value: V) -> Self where
K: AsRef<str>,
V: ToString,
pub fn query<K, V>(self, key: K, value: V) -> Self where
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) -> Self where
P: IntoIterator,
P::Item: Borrow<(K, V)>,
K: AsRef<str>,
V: ToString,
pub fn queries<P, K, V>(self, pairs: P) -> Self where
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
Set 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
Set 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
Set 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
Set 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
Set 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
Set 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 insert_header<H, V>(self, header: H, value: V) -> Self where
H: IntoHeaderName,
V: TryInto<HeaderValue>,
pub fn insert_header<H, V>(self, header: H, value: V) -> Self where
H: IntoHeaderName,
V: TryInto<HeaderValue>,
Modify a header for this request.
If the header is already present, the value will be replaced. If you wish to append a new header,
use header_append
.
sourcepub fn append_header<H, V>(self, header: H, value: V) -> Self where
H: IntoHeaderName,
V: TryInto<HeaderValue>,
pub fn append_header<H, V>(self, header: H, value: V) -> Self where
H: IntoHeaderName,
V: TryInto<HeaderValue>,
Append a new header to this request.
The new header is always appended to the request, even if the header already exists.
Trait Implementations
Auto Trait Implementations
impl !RefUnwindSafe for RequestBuilder
impl Send for RequestBuilder
impl Sync for RequestBuilder
impl Unpin for RequestBuilder
impl !UnwindSafe for RequestBuilder
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> 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