http: add HttpClient trait

gated behind feature "client-trait"

Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
This commit is contained in:
Fabian Grünbichler 2022-06-23 11:56:43 +02:00
parent 94456ee4b1
commit 3c0486be50
3 changed files with 19 additions and 0 deletions

View File

@ -31,6 +31,7 @@ proxmox-lang = { path = "../proxmox-lang", optional = true, version = "1.1" }
default = []
client = [ "futures", "http-helpers", "hyper/full", "openssl", "tokio/io-util", "tokio-openssl" ]
client-trait = [ "http" ]
http-helpers = [ "base64", "http", "proxmox-sys", "serde_json", "url" ]
websocket = [
"base64",

View File

@ -0,0 +1,13 @@
use anyhow::Error;
use http::Response;
pub trait HttpClient<T> {
fn get(&self, uri: &str) -> Result<Response<T>, Error>;
fn post(
&self,
uri: &str,
body: Option<String>,
content_type: Option<&str>,
) -> Result<Response<T>, Error>;
}

View File

@ -13,3 +13,8 @@ pub use proxy_config::ProxyConfig;
#[cfg(feature = "client")]
pub mod client;
#[cfg(feature = "client-trait")]
mod client_trait;
#[cfg(feature = "client-trait")]
pub use client_trait::HttpClient;