pub struct HttpClient { /* private fields */ }Expand description
Authenticated HTTP client for CLI command implementations.
The client covers the transport behavior command authors usually need: auth injection, JSON request/response helpers, structured HTTP errors, idempotent retries, ETag helpers, raw streaming helpers, multipart helpers, and GraphQL envelope decoding.
Implementations§
Source§impl HttpClient
impl HttpClient
Sourcepub fn builder(
base_url: impl Into<String>,
auth: Arc<dyn AuthInjector>,
) -> HttpClientBuilder
pub fn builder( base_url: impl Into<String>, auth: Arc<dyn AuthInjector>, ) -> HttpClientBuilder
Creates a client builder.
Sourcepub fn new(base_url: impl Into<String>, auth: Arc<dyn AuthInjector>) -> Self
pub fn new(base_url: impl Into<String>, auth: Arc<dyn AuthInjector>) -> Self
Creates a client with default settings.
Sourcepub async fn get<T: Default + DeserializeOwned>(&self, path: &str) -> Result<T>
pub async fn get<T: Default + DeserializeOwned>(&self, path: &str) -> Result<T>
Sends GET and decodes a JSON response.
Sourcepub async fn get_without_response(&self, path: &str) -> Result<()>
pub async fn get_without_response(&self, path: &str) -> Result<()>
Sends GET and checks only for success.
Sourcepub async fn post<B: Serialize, T: Default + DeserializeOwned>(
&self,
path: &str,
body: &B,
) -> Result<T>
pub async fn post<B: Serialize, T: Default + DeserializeOwned>( &self, path: &str, body: &B, ) -> Result<T>
Sends POST with a JSON body and decodes a JSON response.
Sourcepub async fn post_without_response<B: Serialize>(
&self,
path: &str,
body: &B,
) -> Result<()>
pub async fn post_without_response<B: Serialize>( &self, path: &str, body: &B, ) -> Result<()>
Sends POST with a JSON body and checks only for success.
Sourcepub async fn put<B: Serialize, T: Default + DeserializeOwned>(
&self,
path: &str,
body: &B,
) -> Result<T>
pub async fn put<B: Serialize, T: Default + DeserializeOwned>( &self, path: &str, body: &B, ) -> Result<T>
Sends PUT with a JSON body and decodes a JSON response.
Sourcepub async fn put_without_response<B: Serialize>(
&self,
path: &str,
body: &B,
) -> Result<()>
pub async fn put_without_response<B: Serialize>( &self, path: &str, body: &B, ) -> Result<()>
Sends PUT with a JSON body and checks only for success.
Sourcepub async fn patch<B: Serialize, T: Default + DeserializeOwned>(
&self,
path: &str,
body: &B,
) -> Result<T>
pub async fn patch<B: Serialize, T: Default + DeserializeOwned>( &self, path: &str, body: &B, ) -> Result<T>
Sends PATCH with a JSON body and decodes a JSON response.
Sourcepub async fn patch_without_response<B: Serialize>(
&self,
path: &str,
body: &B,
) -> Result<()>
pub async fn patch_without_response<B: Serialize>( &self, path: &str, body: &B, ) -> Result<()>
Sends PATCH with a JSON body and checks only for success.
Sourcepub async fn delete_with_body<B: Serialize>(
&self,
path: &str,
body: &B,
) -> Result<()>
pub async fn delete_with_body<B: Serialize>( &self, path: &str, body: &B, ) -> Result<()>
Sends DELETE with a JSON body and checks for success.
Sourcepub async fn get_etag<T: Default + DeserializeOwned>(
&self,
path: &str,
) -> Result<(T, String)>
pub async fn get_etag<T: Default + DeserializeOwned>( &self, path: &str, ) -> Result<(T, String)>
Sends GET and returns decoded JSON plus the ETag header.
Sourcepub async fn get_etag_without_response(&self, path: &str) -> Result<String>
pub async fn get_etag_without_response(&self, path: &str) -> Result<String>
Sends GET and returns only the ETag header after checking success.
Sourcepub async fn put_if_match<B: Serialize, T: Default + DeserializeOwned>(
&self,
path: &str,
body: &B,
etag: &str,
) -> Result<T>
pub async fn put_if_match<B: Serialize, T: Default + DeserializeOwned>( &self, path: &str, body: &B, etag: &str, ) -> Result<T>
Sends PUT with If-Match and decodes a JSON response.
Sourcepub async fn put_if_match_without_response<B: Serialize>(
&self,
path: &str,
body: &B,
etag: &str,
) -> Result<()>
pub async fn put_if_match_without_response<B: Serialize>( &self, path: &str, body: &B, etag: &str, ) -> Result<()>
Sends PUT with If-Match and checks only for success.
Sourcepub async fn get_raw(&self, path: &str, writer: &mut dyn Write) -> Result<()>
pub async fn get_raw(&self, path: &str, writer: &mut dyn Write) -> Result<()>
Streams a raw GET response body into a writer.
Sourcepub async fn post_raw<B: Serialize>(
&self,
path: &str,
body: Option<&B>,
writer: &mut dyn Write,
) -> Result<()>
pub async fn post_raw<B: Serialize>( &self, path: &str, body: Option<&B>, writer: &mut dyn Write, ) -> Result<()>
Sends POST and streams the raw response body into a writer.
Sourcepub async fn do_raw<T: Default + DeserializeOwned>(
&self,
method: Method,
path: &str,
content_type: &str,
body: impl Into<Vec<u8>>,
) -> Result<T>
pub async fn do_raw<T: Default + DeserializeOwned>( &self, method: Method, path: &str, content_type: &str, body: impl Into<Vec<u8>>, ) -> Result<T>
Sends a raw-body request and decodes a JSON response.
Sourcepub async fn do_raw_optional_body<T: Default + DeserializeOwned>(
&self,
method: Method,
path: &str,
content_type: &str,
body: Option<Vec<u8>>,
) -> Result<T>
pub async fn do_raw_optional_body<T: Default + DeserializeOwned>( &self, method: Method, path: &str, content_type: &str, body: Option<Vec<u8>>, ) -> Result<T>
Sends an optional raw-body request and decodes a JSON response.
Sourcepub async fn do_raw_without_response(
&self,
method: Method,
path: &str,
content_type: &str,
body: impl Into<Vec<u8>>,
) -> Result<()>
pub async fn do_raw_without_response( &self, method: Method, path: &str, content_type: &str, body: impl Into<Vec<u8>>, ) -> Result<()>
Sends a raw-body request and checks only for success.
Sourcepub async fn do_raw_optional_body_without_response(
&self,
method: Method,
path: &str,
content_type: &str,
body: Option<Vec<u8>>,
) -> Result<()>
pub async fn do_raw_optional_body_without_response( &self, method: Method, path: &str, content_type: &str, body: Option<Vec<u8>>, ) -> Result<()>
Sends an optional raw-body request and checks only for success.
Sourcepub async fn post_multipart<T: Default + DeserializeOwned>(
&self,
path: &str,
field_name: &str,
file_path: &Path,
) -> Result<T>
pub async fn post_multipart<T: Default + DeserializeOwned>( &self, path: &str, field_name: &str, file_path: &Path, ) -> Result<T>
Sends a multipart file upload and decodes a JSON response.
Sourcepub async fn post_multipart_without_response(
&self,
path: &str,
field_name: &str,
file_path: &Path,
) -> Result<()>
pub async fn post_multipart_without_response( &self, path: &str, field_name: &str, file_path: &Path, ) -> Result<()>
Sends a multipart file upload and checks only for success.
Sourcepub async fn post_multipart_with_fields<T: Default + DeserializeOwned>(
&self,
path: &str,
file_field: &str,
file_path: &Path,
fields: &BTreeMap<String, String>,
) -> Result<T>
pub async fn post_multipart_with_fields<T: Default + DeserializeOwned>( &self, path: &str, file_field: &str, file_path: &Path, fields: &BTreeMap<String, String>, ) -> Result<T>
Sends a multipart file upload with fields and decodes a JSON response.
Sourcepub async fn post_multipart_with_fields_without_response(
&self,
path: &str,
file_field: &str,
file_path: &Path,
fields: &BTreeMap<String, String>,
) -> Result<()>
pub async fn post_multipart_with_fields_without_response( &self, path: &str, file_field: &str, file_path: &Path, fields: &BTreeMap<String, String>, ) -> Result<()>
Sends a multipart file upload with fields and checks only for success.
Sourcepub async fn post_multipart_fields<T: Default + DeserializeOwned>(
&self,
path: &str,
fields: &BTreeMap<String, String>,
) -> Result<T>
pub async fn post_multipart_fields<T: Default + DeserializeOwned>( &self, path: &str, fields: &BTreeMap<String, String>, ) -> Result<T>
Sends multipart form fields without a file and decodes a JSON response.
Sourcepub async fn post_multipart_fields_without_response(
&self,
path: &str,
fields: &BTreeMap<String, String>,
) -> Result<()>
pub async fn post_multipart_fields_without_response( &self, path: &str, fields: &BTreeMap<String, String>, ) -> Result<()>
Sends multipart form fields without a file and checks only for success.
Sourcepub async fn post_graphql<T: DeserializeOwned + Default>(
&self,
path: &str,
query: &str,
variables: BTreeMap<String, Value>,
) -> Result<T>
pub async fn post_graphql<T: DeserializeOwned + Default>( &self, path: &str, query: &str, variables: BTreeMap<String, Value>, ) -> Result<T>
Sends a GraphQL request and decodes the data envelope into a value.
Sourcepub async fn post_graphql_optional_variables<T: DeserializeOwned + Default>(
&self,
path: &str,
query: &str,
variables: Option<BTreeMap<String, Value>>,
) -> Result<T>
pub async fn post_graphql_optional_variables<T: DeserializeOwned + Default>( &self, path: &str, query: &str, variables: Option<BTreeMap<String, Value>>, ) -> Result<T>
Sends a GraphQL request with optional variables and decodes data.
Sourcepub async fn post_graphql_without_response(
&self,
path: &str,
query: &str,
variables: BTreeMap<String, Value>,
) -> Result<()>
pub async fn post_graphql_without_response( &self, path: &str, query: &str, variables: BTreeMap<String, Value>, ) -> Result<()>
Sends a GraphQL request and checks only for GraphQL/HTTP success.
Sourcepub async fn post_graphql_optional_variables_without_response(
&self,
path: &str,
query: &str,
variables: Option<BTreeMap<String, Value>>,
) -> Result<()>
pub async fn post_graphql_optional_variables_without_response( &self, path: &str, query: &str, variables: Option<BTreeMap<String, Value>>, ) -> Result<()>
Sends a GraphQL request with optional variables and checks only for success.
Trait Implementations§
Source§impl Clone for HttpClient
impl Clone for HttpClient
Source§fn clone(&self) -> HttpClient
fn clone(&self) -> HttpClient
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more