pub trait HttpClient: Send + Sync {
// Required methods
async fn get_json(&self, url: &str) -> Result<Value, Error>;
async fn post_form(
&self,
url: &str,
params: &[(&str, &str)],
) -> Result<Value, Error>;
async fn post_json_bearer(
&self,
url: &str,
body: &Value,
token: &str,
) -> Result<Value, Error>;
async fn post_json(&self, url: &str, body: &Value) -> Result<Value, Error>;
async fn get(&self, url: &str) -> Result<HttpResponse, Error>;
async fn post_raw(
&self,
url: &str,
body: &[u8],
content_type: &str,
) -> Result<HttpResponse, Error>;
}Expand description
Async HTTP client trait for BaseID protocol network requests.
All protocol crates (OID4VCI, OID4VP, SIOPv2, DIDComm) accept this trait for dependency injection and testability.
Required Methods§
Sourceasync fn get_json(&self, url: &str) -> Result<Value, Error>
async fn get_json(&self, url: &str) -> Result<Value, Error>
Perform a GET request and parse the JSON response.
Sourceasync fn post_form(
&self,
url: &str,
params: &[(&str, &str)],
) -> Result<Value, Error>
async fn post_form( &self, url: &str, params: &[(&str, &str)], ) -> Result<Value, Error>
Perform a POST request with form-encoded parameters and parse the JSON response.
Sourceasync fn post_json_bearer(
&self,
url: &str,
body: &Value,
token: &str,
) -> Result<Value, Error>
async fn post_json_bearer( &self, url: &str, body: &Value, token: &str, ) -> Result<Value, Error>
Perform a POST request with a JSON body and bearer token, returning the JSON response.
Sourceasync fn post_json(&self, url: &str, body: &Value) -> Result<Value, Error>
async fn post_json(&self, url: &str, body: &Value) -> Result<Value, Error>
Perform a POST request with a JSON body (no auth), returning the JSON response.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.
Implementors§
impl HttpClient for MockHttpClient
impl HttpClient for ReqwestHttpClient
Available on crate feature
http-reqwest only.