#[non_exhaustive]pub struct HttpRequest {
pub method: Method,
pub url: String,
pub headers: Vec<(String, String)>,
pub body: Option<Vec<u8>>,
}Expand description
A request sent with a HttpClient. The body is always plain bytes, so a client only
has to send them.
Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.method: Method§url: String§headers: Vec<(String, String)>§body: Option<Vec<u8>>Implementations§
Source§impl HttpRequest
impl HttpRequest
Sourcepub fn new(method: Method, url: impl Into<String>) -> HttpRequest
pub fn new(method: Method, url: impl Into<String>) -> HttpRequest
Creates a request without headers and body.
Sourcepub fn get(url: impl Into<String>) -> HttpRequest
pub fn get(url: impl Into<String>) -> HttpRequest
Creates a GET request.
Sourcepub fn post(url: impl Into<String>) -> HttpRequest
pub fn post(url: impl Into<String>) -> HttpRequest
Creates a POST request.
Sourcepub fn delete(url: impl Into<String>) -> HttpRequest
pub fn delete(url: impl Into<String>) -> HttpRequest
Creates a DELETE request.
Sourcepub fn with_header(
self,
name: impl Into<String>,
value: impl Into<String>,
) -> HttpRequest
pub fn with_header( self, name: impl Into<String>, value: impl Into<String>, ) -> HttpRequest
Adds a header.
Sourcepub fn with_bearer_token(self, token: &str) -> HttpRequest
pub fn with_bearer_token(self, token: &str) -> HttpRequest
Adds Authorization: Bearer <token>. An empty token adds nothing, for servers without
authentication.
Sourcepub fn with_json(self, body: &impl Serialize) -> Result<HttpRequest, HttpError>
pub fn with_json(self, body: &impl Serialize) -> Result<HttpRequest, HttpError>
Sets a JSON body and its Content-Type.
Sourcepub fn with_multipart(self, form: Multipart) -> HttpRequest
pub fn with_multipart(self, form: Multipart) -> HttpRequest
Sets a multipart/form-data body and its Content-Type.
Trait Implementations§
Source§impl Clone for HttpRequest
impl Clone for HttpRequest
Source§fn clone(&self) -> HttpRequest
fn clone(&self) -> HttpRequest
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for HttpRequest
impl Debug for HttpRequest
Source§impl PartialEq for HttpRequest
impl PartialEq for HttpRequest
impl StructuralPartialEq for HttpRequest
Auto Trait Implementations§
impl Forget for HttpRequest
impl Freeze for HttpRequest
impl Move for HttpRequest
impl RefUnwindSafe for HttpRequest
impl Send for HttpRequest
impl Sync for HttpRequest
impl Unpin for HttpRequest
impl UnsafeUnpin for HttpRequest
impl UnwindSafe for HttpRequest
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