pub struct RequestBuilder<C = HttpConnector> { /* private fields */ }Expand description
Builder for a single HTTP request.
Created via Client::get(), Client::post(), etc.
Implementations§
Source§impl<C> RequestBuilder<C>
impl<C> RequestBuilder<C>
Sourcepub fn header(self, key: &str, value: &str) -> Result<Self, OxiHttpError>
pub fn header(self, key: &str, value: &str) -> Result<Self, OxiHttpError>
Add a request header.
Sourcepub fn bearer_token(self, token: &str) -> Result<Self, OxiHttpError>
pub fn bearer_token(self, token: &str) -> Result<Self, OxiHttpError>
Set a Bearer token for the Authorization header.
Sourcepub fn basic_auth(
self,
username: &str,
password: Option<&str>,
) -> Result<Self, OxiHttpError>
pub fn basic_auth( self, username: &str, password: Option<&str>, ) -> Result<Self, OxiHttpError>
Set Basic authentication for the Authorization header.
Sourcepub fn json<T: Serialize>(self, value: &T) -> Result<Self, OxiHttpError>
pub fn json<T: Serialize>(self, value: &T) -> Result<Self, OxiHttpError>
Set the request body as JSON, automatically setting the Content-Type header.
Sourcepub fn multipart(self, builder: MultipartBuilder) -> Self
pub fn multipart(self, builder: MultipartBuilder) -> Self
Set the request body from a MultipartBuilder, automatically setting
the Content-Type: multipart/form-data; boundary=… header.
The Content-Type is only set if the caller has not already provided one.
This allows overriding the header with an explicit .header() call made
before .multipart().
§Example
use oxihttp_client::Client;
use oxihttp_core::MultipartBuilder;
let client = Client::builder().build()?;
let builder = MultipartBuilder::new().add_text("field", "value");
let resp = client.post("http://example.com/upload")?
.multipart(builder)
.send()
.await?;Sourcepub async fn send(self) -> Result<Response, OxiHttpError>
pub async fn send(self) -> Result<Response, OxiHttpError>
Send the request and return the response.
Respects retry policy and per-request timeout.
Before the first attempt the before_request hook is called on each
registered middleware; after a successful response after_response is
called with the final status and elapsed wall-clock time.