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
26
27
28
29
30
31
32
33
34
35
extern crate reqwest;
use crate::error::Error;
use reqwest::header::HeaderMap;
use reqwest::StatusCode;
use serde::de::DeserializeOwned;
pub struct Response(reqwest::Response);
impl Response {
pub fn new(response: reqwest::Response) -> Self {
Self(response)
}
pub fn status_code(&self) -> StatusCode {
self.0.status()
}
pub fn headers(&self) -> &HeaderMap {
self.0.headers()
}
pub async fn read_body<B>(self) -> Result<B, Error>
where
B: DeserializeOwned,
{
let body = self.0.json::<B>().await?;
Ok(body)
}
}