Skip to main content

HttpClient

Struct HttpClient 

Source
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

Source

pub fn builder( base_url: impl Into<String>, auth: Arc<dyn AuthInjector>, ) -> HttpClientBuilder

Creates a client builder.

Source

pub fn new(base_url: impl Into<String>, auth: Arc<dyn AuthInjector>) -> Self

Creates a client with default settings.

Source

pub async fn get<T: Default + DeserializeOwned>(&self, path: &str) -> Result<T>

Sends GET and decodes a JSON response.

Source

pub async fn get_without_response(&self, path: &str) -> Result<()>

Sends GET and checks only for success.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub async fn delete(&self, path: &str) -> Result<()>

Sends DELETE and checks for success.

Source

pub async fn delete_with_body<B: Serialize>( &self, path: &str, body: &B, ) -> Result<()>

Sends DELETE with a JSON body and checks for success.

Source

pub async fn get_etag<T: Default + DeserializeOwned>( &self, path: &str, ) -> Result<(T, String)>

Sends GET and returns decoded JSON plus the ETag header.

Source

pub async fn get_etag_without_response(&self, path: &str) -> Result<String>

Sends GET and returns only the ETag header after checking success.

Source

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.

Source

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.

Source

pub async fn get_raw(&self, path: &str, writer: &mut dyn Write) -> Result<()>

Streams a raw GET response body into a writer.

Source

pub async fn get_bytes(&self, path: &str) -> Result<Vec<u8>>

Sends GET and returns the raw response body as bytes.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub async fn post_graphql_into<T: DeserializeOwned>( &self, path: &str, query: &str, variables: BTreeMap<String, Value>, result: &mut T, ) -> Result<()>

Sends a GraphQL request and decodes data into an existing value.

Source

pub async fn post_graphql_optional_variables_into<T: DeserializeOwned>( &self, path: &str, query: &str, variables: Option<BTreeMap<String, Value>>, result: &mut T, ) -> Result<()>

Sends a GraphQL request with optional variables and decodes into an existing value.

Trait Implementations§

Source§

impl Clone for HttpClient

Source§

fn clone(&self) -> HttpClient

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for HttpClient

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more