pub struct PreparedRequest {
pub method: HttpMethod,
pub url: Url,
pub headers: HashMap<String, String>,
pub body: Option<String>,
}Expand description
A fully-assembled HTTP request: method, URL, headers, optional body.
Independent of any HTTP client. Callers translate the fields into
their transport’s request builder (reqwest::Request, ureq::Request,
…) before dispatching.
Fields§
§method: HttpMethodHTTP verb.
url: UrlFully-qualified endpoint URL (with any query string already appended).
headers: HashMap<String, String>Extra headers to attach to the request. Content-Type is set
automatically by PreparedRequest::with_json_body and
PreparedRequest::with_raw_body.
body: Option<String>Request body, if any. None for GET / header-only requests.
Implementations§
Source§impl PreparedRequest
impl PreparedRequest
Sourcepub fn new(method: HttpMethod, url: Url) -> Self
pub fn new(method: HttpMethod, url: Url) -> Self
Build an empty request with the given method and URL.
Sourcepub fn with_header(
self,
key: impl Into<String>,
value: impl Into<String>,
) -> Self
pub fn with_header( self, key: impl Into<String>, value: impl Into<String>, ) -> Self
Insert or overwrite a header. Chainable.
Sourcepub fn with_json_body<T: Serialize>(self, data: &T) -> Result<Self>
pub fn with_json_body<T: Serialize>(self, data: &T) -> Result<Self>
Serialise data as JSON, attach as body, and set
Content-Type: application/json. Fails only if serialisation itself fails.
Sourcepub fn with_raw_body(self, body: String, content_type: &str) -> Self
pub fn with_raw_body(self, body: String, content_type: &str) -> Self
Attach a raw string body with a caller-provided Content-Type.
Trait Implementations§
Source§impl Clone for PreparedRequest
impl Clone for PreparedRequest
Source§fn clone(&self) -> PreparedRequest
fn clone(&self) -> PreparedRequest
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more