pub struct RequestBuilder { /* private fields */ }Implementations§
Source§impl RequestBuilder
impl RequestBuilder
Sourcepub fn header<K, V>(self, key: K, value: V) -> Self
pub fn header<K, V>(self, key: K, value: V) -> Self
Add a header to the Request.
let resp = Client::new().get("https://httpbin.org/get")
.header("Content-Type", "application/json")
.send()?;Sourcepub fn headers<K, V, I>(self, headers: I) -> Self
pub fn headers<K, V, I>(self, headers: I) -> Self
Add a set of headers to the Request.
Existing headers will be overwritten.
let resp = Client::new().get("https://httpbin.org/get")
.headers([("Content-Type", "application/json"), ("Accept", "*/*")])
.send()?;Sourcepub fn query<T: Serialize + ?Sized>(self, query: &T) -> Self
pub fn query<T: Serialize + ?Sized>(self, query: &T) -> Self
Modify the query string of the Request URL.
let resp = Client::new().get("https://httpbin.org/get")
.query(&[("a", "b"), ("c", "d")])
.send()?;Sourcepub fn body(self, body: &[u8]) -> Self
pub fn body(self, body: &[u8]) -> Self
Set the request body.
let resp = Client::new().post("https://httpbin.org/post")
.body("hello".as_bytes())
.send()?;Sourcepub fn json<T: Serialize + ?Sized>(self, json: &T) -> Self
Available on crate feature json only.
pub fn json<T: Serialize + ?Sized>(self, json: &T) -> Self
json only.Send a JSON body.
§Optional
This requires the json feature enabled.
let resp = Client::new().post("https://httpbin.org/post")
.json(&HashMap::from([("data", "hello")]))
.send()?;Sourcepub fn form<T: Serialize + ?Sized>(self, form: &T) -> Self
pub fn form<T: Serialize + ?Sized>(self, form: &T) -> Self
Send a form body.
let resp = Client::new().post("https://httpbin.org/post")
.form(&[("a", "b"), ("c", "d")])
.send()?;Sourcepub fn connect_timeout(self, timeout: Duration) -> Self
pub fn connect_timeout(self, timeout: Duration) -> Self
Set the timeout for the initial connect to the HTTP Server.
let resp = Client::new().post("https://httpbin.org/post")
.connect_timeout(Duration::from_secs(5))
.send()?;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§
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