HttpClient

Trait HttpClient 

Source
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§

Source

async fn get_json(&self, url: &str) -> Result<Value, Error>

Perform a GET request and parse the JSON response.

Source

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.

Source

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.

Source

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.

Source

async fn get(&self, url: &str) -> Result<HttpResponse, Error>

Perform a raw GET request, returning the full response.

Source

async fn post_raw( &self, url: &str, body: &[u8], content_type: &str, ) -> Result<HttpResponse, Error>

Perform a raw POST request with bytes body and content type.

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§

Source§

impl HttpClient for MockHttpClient

Source§

impl HttpClient for ReqwestHttpClient

Available on crate feature http-reqwest only.