pub struct Request {
pub method: String,
pub url: String,
pub headers: Vec<(String, String)>,
pub body: Vec<u8>,
pub timeout_ms: u32,
pub max_body: usize,
}Expand description
A request. Build it with Request::get, Request::post or
Request::new, then Request::send it.
Fields§
§method: String§url: String§headers: Vec<(String, String)>§body: Vec<u8>§timeout_ms: u32The whole exchange: connecting, the response’s headers and its body.
max_body: usizeA body longer than this is refused with Error::Invalid (its
Content-Length before anything is read, or as it streams in).
Implementations§
Source§impl Request
impl Request
Sourcepub fn new(method: &str, url: &str) -> Self
pub fn new(method: &str, url: &str) -> Self
method (GET, POST, PATCH, …) to url (https://host/path?query).
pub fn get(url: &str) -> Self
pub fn post(url: &str) -> Self
Sourcepub fn header(self, name: &str, value: &str) -> Self
pub fn header(self, name: &str, value: &str) -> Self
Adds a request header (Authorization, Accept, …).
pub fn body(self, body: impl Into<Vec<u8>>) -> Self
Sourcepub fn json<T: Serialize + ?Sized>(self, value: &T) -> Result<Self>
pub fn json<T: Serialize + ?Sized>(self, value: &T) -> Result<Self>
A JSON body and its Content-Type.
Sourcepub fn timeout_ms(self, timeout_ms: u32) -> Self
pub fn timeout_ms(self, timeout_ms: u32) -> Self
The whole exchange may take timeout_ms; past it the request fails
with Error::Unavailable("timeout").
Sourcepub fn max_body(self, bytes: usize) -> Self
pub fn max_body(self, bytes: usize) -> Self
Reads at most bytes of body; a longer one fails with
Error::Invalid.
Trait Implementations§
impl Eq for Request
impl StructuralPartialEq for Request
Auto Trait Implementations§
impl Freeze for Request
impl RefUnwindSafe for Request
impl Send for Request
impl Sync for Request
impl Unpin for Request
impl UnsafeUnpin for Request
impl UnwindSafe for Request
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