use crate::api::API_VERSION;
use http::HeaderMap;
use reqwest;
pub(crate) async fn delete(
api_key: &str,
server: &str,
endpoint: &str,
) -> Result<reqwest::Response, reqwest::Error> {
let mut map = HeaderMap::new();
let bearer = format!("Bearer {}", api_key);
map.insert("ACCEPT", "application/json".parse().unwrap());
map.insert("Authorization", bearer.parse().unwrap());
map.insert("Anytype-Version", API_VERSION.parse().unwrap());
let client = reqwest::Client::new(); let url = format!("{}{}", server, endpoint);
let response = client.delete(url).headers(map).send().await;
response
}
pub(crate) async fn get(
api_key: &str,
server: &str,
endpoint: &str,
) -> Result<reqwest::Response, reqwest::Error> {
let mut map = HeaderMap::new();
let bearer = format!("Bearer {}", api_key);
map.insert("ACCEPT", "application/json".parse().unwrap());
map.insert("Authorization", bearer.parse().unwrap());
map.insert("Anytype-Version", API_VERSION.parse().unwrap());
let client = reqwest::Client::new(); let url = format!("{}{}", server, endpoint);
client.get(url).headers(map).send().await
}
pub(crate) async fn post(
api_key: &str,
server: &str,
endpoint: &str,
body: &str,
) -> Result<reqwest::Response, reqwest::Error> {
let mut map = HeaderMap::new();
let bearer = format!("Bearer {}", api_key);
map.insert("ACCEPT", "application/json".parse().unwrap());
map.insert("Authorization", bearer.parse().unwrap());
map.insert("Anytype-Version", API_VERSION.parse().unwrap());
let client = reqwest::Client::new(); let url = format!("{}{}", server, endpoint);
let body = format!("{}", body);
client.post(url).headers(map).body(body).send().await
}
pub(crate) async fn patch(
api_key: &str,
server: &str,
endpoint: &str,
body: &str,
) -> Result<reqwest::Response, reqwest::Error> {
let mut map = HeaderMap::new();
let bearer = format!("Bearer {}", api_key);
map.insert("ACCEPT", "application/json".parse().unwrap());
map.insert("Authorization", bearer.parse().unwrap());
map.insert("Anytype-Version", API_VERSION.parse().unwrap());
let client = reqwest::Client::new(); let url = format!("{}{}", server, endpoint);
client
.patch(url)
.headers(map)
.body(body.to_string())
.send()
.await
}