pub trait HttpClient {
// Required methods
fn post(
&self,
url: &str,
headers: &[(&str, &str)],
payload: &str,
) -> Result<String, HttpClientError>;
fn get(
&self,
url: &str,
params: &[(&str, &str)],
queries: &[(&str, &str)],
) -> Result<String, HttpClientError>;
}
Expand description
A trait defining the interface for an HTTP client.
Required Methods§
Sourcefn post(
&self,
url: &str,
headers: &[(&str, &str)],
payload: &str,
) -> Result<String, HttpClientError>
fn post( &self, url: &str, headers: &[(&str, &str)], payload: &str, ) -> Result<String, HttpClientError>
Sends an HTTP POST request.
§Arguments
url
- The URL to which the POST request will be sent.headers
- A slice of tuples representing HTTP headers.payload
- The payload of the POST request.
§Returns
Returns a Result
containing the response as a String
on success,
or an error of type HttpClientError
on failure.
Sourcefn get(
&self,
url: &str,
params: &[(&str, &str)],
queries: &[(&str, &str)],
) -> Result<String, HttpClientError>
fn get( &self, url: &str, params: &[(&str, &str)], queries: &[(&str, &str)], ) -> Result<String, HttpClientError>
Sends an HTTP GET request.
§Arguments
url
- The URL to which the GET request will be sent.params
- A slice of tuples representing HTTP headers.queries
- A slice of tuples representing URL query parameters.
§Returns
Returns a Result
containing the response as a String
on success,
or an error of type HttpClientError
on failure.