pub struct Request {
pub url: String,
pub user_agent: Option<String>,
}Expand description
Builder for an HTTP GET request, holding the target URL and optional headers before the request is sent.
Fields§
§url: StringThe target URL to request.
user_agent: Option<String>Optional value for the User-Agent request header.
Implementations§
Source§impl Request
impl Request
Sourcepub fn new(url: impl Into<String>) -> Self
pub fn new(url: impl Into<String>) -> Self
Creates a new request targeting url with no custom headers set.
Sourcepub fn with_user_agent(self, user_agent: impl Into<String>) -> Self
pub fn with_user_agent(self, user_agent: impl Into<String>) -> Self
Sets the User-Agent header to send with the request and returns the
updated request for chaining.
Sourcepub async fn get(self) -> Result<String>
pub async fn get(self) -> Result<String>
Sends the configured GET request and returns the response body as a string. Returns an error on a non-success HTTP status.
Sourcepub async fn get_bytes(self) -> Result<Vec<u8>>
pub async fn get_bytes(self) -> Result<Vec<u8>>
Sends the configured GET request and returns the response body as raw bytes. Returns an error on a non-success HTTP status.
Sourcepub async fn get_json<T: DeserializeOwned + 'static>(self) -> Result<T>
pub async fn get_json<T: DeserializeOwned + 'static>(self) -> Result<T>
Sends the configured GET request and deserializes the response body
from JSON into T. Returns an error on a non-success HTTP status or
if deserialization fails.
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