pub struct RequestBuilder { /* private fields */ }Expand description
Fluent builder for HttpRequest.
Single-purpose, chainable. Each method returns &mut Self for fluent
chaining; call RequestBuilder::build to obtain the final
HttpRequest.
§Examples
ⓘ
use http_request::{RequestBuilder, Proxy};
// sync GET
let mut req = RequestBuilder::new()
.get("https://example.com/api")
.header("Accept", "application/json")
.timeout(5_000)
.build();
let _resp = req.send();
// async POST with JSON body
let req = RequestBuilder::new()
.post("https://example.com/api")
.body_json(&serde_json::json!({"k": "v"}))
.header("Content-Type", "application/json")
.proxy(Proxy::https("127.0.0.1", 7890).auth("u", "p"))
.build();
let _resp = req.send_async().await;Implementations§
Source§impl RequestBuilder
impl RequestBuilder
Sourcepub fn get_request_mut(&mut self) -> &mut HttpRequest
pub fn get_request_mut(&mut self) -> &mut HttpRequest
Returns the underlying request mutably.
§Returns
&mut HttpRequest- The mutable request being built.
Sourcepub fn remove_header<K: AsRef<str>>(&mut self, key: K) -> &mut Self
pub fn remove_header<K: AsRef<str>>(&mut self, key: K) -> &mut Self
Sourcepub fn clear_headers(&mut self) -> &mut Self
pub fn clear_headers(&mut self) -> &mut Self
Sourcepub fn buffer_size(&mut self, n: usize) -> &mut Self
pub fn buffer_size(&mut self, n: usize) -> &mut Self
Sourcepub fn http1_1_only(&mut self) -> &mut Self
pub fn http1_1_only(&mut self) -> &mut Self
Sourcepub fn http2_only(&mut self) -> &mut Self
pub fn http2_only(&mut self) -> &mut Self
Sourcepub fn redirect(&mut self) -> &mut Self
pub fn redirect(&mut self) -> &mut Self
Enable auto-follow of 3xx redirects.
§Returns
&mut Self- A mutable reference to this builder for chaining.
Sourcepub fn no_redirect(&mut self) -> &mut Self
pub fn no_redirect(&mut self) -> &mut Self
Disable auto-follow of 3xx redirects (default).
§Returns
&mut Self- A mutable reference to this builder for chaining.
Sourcepub fn max_redirect_times(&mut self, n: usize) -> &mut Self
pub fn max_redirect_times(&mut self, n: usize) -> &mut Self
Sourcepub fn decode(&mut self) -> &mut Self
pub fn decode(&mut self) -> &mut Self
Enable automatic response body decompression (gzip / deflate / br).
§Returns
&mut Self- A mutable reference to this builder for chaining.
Sourcepub fn no_decode(&mut self) -> &mut Self
pub fn no_decode(&mut self) -> &mut Self
Disable automatic response body decompression.
§Returns
&mut Self- A mutable reference to this builder for chaining.
Sourcepub fn proxy(&mut self, proxy: Proxy) -> &mut Self
pub fn proxy(&mut self, proxy: Proxy) -> &mut Self
Set the proxy configuration. Pass None (via [Proxy::default()) to
clear an existing proxy.
Construct via Proxy::http / Proxy::https / Proxy::socks5
and optionally chain .auth(user, pass).
§Arguments
Proxy- The proxy configuration to apply to the request.
§Returns
&mut Self- A mutable reference to this builder for chaining.
Sourcepub fn no_proxy(&mut self) -> &mut Self
pub fn no_proxy(&mut self) -> &mut Self
Clear the proxy (use direct connection).
§Returns
&mut Self- A mutable reference to this builder for chaining.
Sourcepub fn build(&mut self) -> HttpRequest
pub fn build(&mut self) -> HttpRequest
Finalise the builder and return the HttpRequest.
§Returns
HttpRequest- The finalised request, leaving the builder empty.
Trait Implementations§
Source§impl Clone for RequestBuilder
impl Clone for RequestBuilder
Source§impl Debug for RequestBuilder
impl Debug for RequestBuilder
Auto Trait Implementations§
impl Freeze for RequestBuilder
impl RefUnwindSafe for RequestBuilder
impl Send for RequestBuilder
impl Sync for RequestBuilder
impl Unpin for RequestBuilder
impl UnsafeUnpin for RequestBuilder
impl UnwindSafe for RequestBuilder
Blanket Implementations§
impl<T> AnySend for T
impl<T> AnySendClone for T
impl<T> AnySendSync for T
impl<T> AnySendSyncClone for T
impl<T> AnySync for T
impl<T> AnySyncClone for T
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