1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
use anyhow::Result;
pub async fn http_post<I: AsRef<str>>(url: I, body: String) -> Result<String> {
let url = url.as_ref();
info!("HTTP POST to {}", url);
let resp = reqwest::Client::new().post(url).body(body).send().await?;
let status = resp.status();
let text = resp.text().await?;
if status.is_client_error() || status.is_server_error() {
bail!("HTTP error {}: {}", status, text);
}
Ok(text)
}
pub async fn http_get<I: AsRef<str>>(url: I) -> Result<Vec<u8>> {
let url = url.as_ref();
info!("HTTP GET {}", url);
let resp = reqwest::get(url).await?.error_for_status()?.bytes().await?;
Ok(resp.to_vec())
}