pub struct RequestBuilder<'a> { /* private fields */ }Expand description
A wrapper around middleware::RequestBuilder that provides an
ergonomic API and resolves the URL against the client’s base URL.
Implementations§
Source§impl<'a> RequestBuilder<'a>
impl<'a> RequestBuilder<'a>
Sourcepub fn with_extension<T: Clone + Send + Sync + 'static>(self, value: T) -> Self
pub fn with_extension<T: Clone + Send + Sync + 'static>(self, value: T) -> Self
Attach request-scoped typed data, carried through every middleware
in the chain’s shared extension map (and surviving across retry
attempts). Middleware read it with extensions.get::<T>().
Sourcepub fn header<K, V>(self, key: K, value: V) -> Selfwhere
HeaderName: TryFrom<K>,
<HeaderName as TryFrom<K>>::Error: Into<Error>,
HeaderValue: TryFrom<V>,
<HeaderValue as TryFrom<V>>::Error: Into<Error>,
pub fn header<K, V>(self, key: K, value: V) -> Selfwhere
HeaderName: TryFrom<K>,
<HeaderName as TryFrom<K>>::Error: Into<Error>,
HeaderValue: TryFrom<V>,
<HeaderValue as TryFrom<V>>::Error: Into<Error>,
Add a single header.
Sourcepub fn json<T: Serialize + ?Sized>(self, body: &T) -> Self
pub fn json<T: Serialize + ?Sized>(self, body: &T) -> Self
Set a JSON body (requires the json feature).
Sourcepub fn bearer_auth(self, token: impl Display) -> Self
pub fn bearer_auth(self, token: impl Display) -> Self
Set a Bearer authorization token.
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
Set HTTP basic auth credentials.
Sourcepub fn form<T: Serialize + ?Sized>(self, form: &T) -> Self
pub fn form<T: Serialize + ?Sized>(self, form: &T) -> Self
Set form-encoded body from a serializable value.
Sourcepub async fn send(self) -> Result<Response, FetchError>
pub async fn send(self) -> Result<Response, FetchError>
Send the request.
Sourcepub async fn json_response<T: DeserializeOwned>(self) -> Result<T, FetchError>
pub async fn json_response<T: DeserializeOwned>(self) -> Result<T, FetchError>
Send the request and deserialize the JSON response (requires the
json feature).
Auto Trait Implementations§
impl<'a> !Freeze for RequestBuilder<'a>
impl<'a> !RefUnwindSafe for RequestBuilder<'a>
impl<'a> !UnwindSafe for RequestBuilder<'a>
impl<'a> Send for RequestBuilder<'a>
impl<'a> Sync for RequestBuilder<'a>
impl<'a> Unpin for RequestBuilder<'a>
impl<'a> UnsafeUnpin for RequestBuilder<'a>
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