reqores/client/
client_request.rs1use serde::de::DeserializeOwned;
2
3use crate::HttpMethod;
4
5use super::ClientResponse;
6
7pub mod headers {
9 pub fn content_type_json_utf8() -> (String, String) {
11 (
12 "Content-Type".to_string(),
13 "application/json; charset=UTF-8".to_string(),
14 )
15 }
16}
17
18pub trait ClientRequest {
20 type Response: DeserializeOwned;
22
23 fn headers(&self) -> Vec<(String, String)> {
27 vec![headers::content_type_json_utf8()]
28 }
29
30 fn url(&self) -> String;
32
33 fn body(&self) -> Option<String> {
35 None
36 }
37
38 fn method(&self) -> HttpMethod;
40
41 fn deserialize(&self, response: &dyn ClientResponse) -> Result<Self::Response, String> {
45 serde_json::from_slice(response.body()).map_err(|e| e.to_string())
46 }
47}