1pub use anyhow::{anyhow, Result};
2use futures::future::BoxFuture;
3use std::sync::Arc;
4pub use surf::{
5 http::{Method, Response as ServerResponse},
6 Request, Response, Url,
7};
8
9pub trait HttpClient: Send + Sync {
10 fn send<'a>(&'a self, req: Request) -> BoxFuture<'a, Result<Response>>;
11}
12
13pub fn client() -> Arc<dyn HttpClient> {
14 Arc::new(surf::client())
15}
16
17impl HttpClient for surf::Client {
18 fn send<'a>(&'a self, req: Request) -> BoxFuture<'a, Result<Response>> {
19 Box::pin(async move {
20 Ok(self
21 .send(req)
22 .await
23 .map_err(|e| anyhow!("http request failed: {}", e))?)
24 })
25 }
26}