use reqwest::Response;
use super::core::{PublicStorage, SessionStorage};
use super::resource::{IntoPubkyResource, IntoResourcePath};
use crate::Result;
use crate::util::check_http_status;
impl SessionStorage {
pub async fn get_json<P, T>(&self, path: P) -> Result<T>
where
P: IntoResourcePath + Send,
T: serde::de::DeserializeOwned,
{
let resp = self
.request(reqwest::Method::GET, path)
.await?
.header(reqwest::header::ACCEPT, "application/json")
.send()
.await?;
let resp = check_http_status(resp).await?;
Ok(resp.json::<T>().await?)
}
pub async fn put_json<P, B>(&self, path: P, body: &B) -> Result<Response>
where
P: IntoResourcePath + Send,
B: serde::Serialize + Sync + ?Sized,
{
let resp = self
.request(reqwest::Method::PUT, path)
.await?
.json(body)
.send()
.await?;
check_http_status(resp).await
}
}
impl PublicStorage {
pub async fn get_json<A, T>(&self, addr: A) -> Result<T>
where
A: IntoPubkyResource + Send,
T: serde::de::DeserializeOwned,
{
let resp = self
.request(reqwest::Method::GET, addr)
.await?
.header(reqwest::header::ACCEPT, "application/json")
.send()
.await?;
let resp = check_http_status(resp).await?;
Ok(resp.json::<T>().await?)
}
}