pub struct Http { /* private fields */ }Expand description
A cheap-to-clone HTTP client shared across backends.
Implementations§
Source§impl Http
impl Http
Sourcepub fn new() -> Result<Self>
pub fn new() -> Result<Self>
Build a client with sensible defaults (timeout, User-Agent).
§Errors
Returns DataError::Transport if the underlying client cannot be built.
Sourcepub fn with_client(client: Client) -> Self
pub fn with_client(client: Client) -> Self
Wrap an already-configured client (useful in tests).
Sourcepub async fn get_json<T: DeserializeOwned>(
&self,
url: &str,
headers: &[(&str, &str)],
) -> Result<T>
pub async fn get_json<T: DeserializeOwned>( &self, url: &str, headers: &[(&str, &str)], ) -> Result<T>
Fetch url and deserialize the JSON body into T.
headers is a list of (name, value) pairs added to the request, used
by backends for API-key auth.
§Errors
DataError::Transporton connection/timeout failures.DataError::RateLimitedon HTTP 429.DataError::Statuson other non-success responses.DataError::Decodeif the body is not valid JSON forT.
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for Http
impl !UnwindSafe for Http
impl Freeze for Http
impl Send for Http
impl Sync for Http
impl Unpin for Http
impl UnsafeUnpin for Http
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