Struct aws_smithy_client::Client
source · pub struct Client<Connector = DynConnector, Middleware = DynMiddleware<Connector>, RetryPolicy = Standard> { /* private fields */ }
Expand description
Smithy service client.
The service client is customizable in a number of ways (see Builder
), but most customers
can stick with the standard constructor provided by Client::new
. It takes only a single
argument, which is the middleware that fills out the http::Request
for each higher-level
operation so that it can ultimately be sent to the remote host. The middleware is responsible
for filling in any request parameters that aren’t specified by the Smithy protocol definition,
such as those used for routing (like the URL), authentication, and authorization.
The middleware takes the form of a tower::Layer
that wraps the actual connection for each
request. The tower::Service
that the middleware produces must accept requests of the type
aws_smithy_http::operation::Request
and return responses of the type
http::Response<SdkBody>
, most likely by modifying the provided request in place, passing it
to the inner service, and then ultimately returning the inner service’s response.
With the hyper
feature enabled, you can construct a Client
directly from a
hyper::Client
using hyper_ext::Adapter::builder
. You can also enable the rustls
or native-tls
features to construct a Client against a standard HTTPS endpoint using Builder::rustls_connector
and
Builder::native_tls_connector
respectively.
Implementations§
source§impl<C, M, R> Client<C, M, R>where
C: SmithyConnector,
M: SmithyMiddleware<C> + Send + Sync + 'static,
R: NewRequestPolicy,
impl<C, M, R> Client<C, M, R>where C: SmithyConnector, M: SmithyMiddleware<C> + Send + Sync + 'static, R: NewRequestPolicy,
sourcepub fn into_dyn_middleware(self) -> Client<C, DynMiddleware<C>, R>
pub fn into_dyn_middleware(self) -> Client<C, DynMiddleware<C>, R>
Erase the middleware type from the client type signature.
This makes the final client type easier to name, at the cost of a marginal increase in
runtime performance. See DynMiddleware
for details.
In practice, you’ll use this method once you’ve constructed a client to your liking:
use aws_smithy_client::{Builder, Client};
struct MyClient {
client: Client<aws_smithy_client::conns::Https>,
}
let client = Builder::new()
.https()
.middleware(tower::layer::util::Identity::new())
.build();
let client = MyClient { client: client.into_dyn_middleware() };
source§impl<C, M, R> Client<C, M, R>where
C: SmithyConnector,
M: SmithyMiddleware<DynConnector> + Send + Sync + 'static,
R: NewRequestPolicy,
impl<C, M, R> Client<C, M, R>where C: SmithyConnector, M: SmithyMiddleware<DynConnector> + Send + Sync + 'static, R: NewRequestPolicy,
sourcepub fn into_dyn_connector(self) -> Client<DynConnector, M, R>
pub fn into_dyn_connector(self) -> Client<DynConnector, M, R>
Erase the connector type from the client type signature.
This makes the final client type easier to name, at the cost of a marginal increase in
runtime performance. See DynConnector
for details.
In practice, you’ll use this method once you’ve constructed a client to your liking:
use aws_smithy_client::{Builder, Client};
struct MyClient {
client: Client<aws_smithy_client::DynConnector, MyMiddleware>,
}
let client = Builder::new()
.https()
.middleware(tower::layer::util::Identity::new())
.build();
let client = MyClient { client: client.into_dyn_connector() };
sourcepub fn into_dyn(self) -> DynClient<R>
pub fn into_dyn(self) -> DynClient<R>
Erase the connector and middleware types from the client type signature.
This makes the final client type easier to name, at the cost of a marginal increase in
runtime performance. See DynConnector
and DynMiddleware
for details.
Note that if you’re using the standard retry mechanism, retry::Standard
, DynClient<R>
is equivalent to Client
with no type arguments.
In practice, you’ll use this method once you’ve constructed a client to your liking:
use aws_smithy_client::{Builder, Client};
struct MyClient {
client: aws_smithy_client::Client,
}
let client = Builder::new()
.https()
.middleware(tower::layer::util::Identity::new())
.build();
let client = MyClient { client: client.into_dyn() };
source§impl<C, M> Client<C, M>where
M: Default,
impl<C, M> Client<C, M>where M: Default,
sourcepub fn new(connector: C) -> Self
pub fn new(connector: C) -> Self
Create a Smithy client from the given connector
, a middleware default, the
standard retry policy, and the
default_async_sleep
sleep implementation.
source§impl<C, M, R> Client<C, M, R>where
C: SmithyConnector,
M: SmithyMiddleware<C>,
R: NewRequestPolicy,
impl<C, M, R> Client<C, M, R>where C: SmithyConnector, M: SmithyMiddleware<C>, R: NewRequestPolicy,
sourcepub async fn call<O, T, E, Retry>(
&self,
op: Operation<O, Retry>
) -> Result<T, SdkError<E>>where
O: Send + Sync,
E: Error + Send + Sync + 'static,
Retry: Send + Sync + ClassifyRetry<SdkSuccess<T>, SdkError<E>>,
R::Policy: SmithyRetryPolicy<O, T, E, Retry>,
Parsed<<M as SmithyMiddleware<C>>::Service, O, Retry>: Service<Operation<O, Retry>, Response = SdkSuccess<T>, Error = SdkError<E>> + Clone,
pub async fn call<O, T, E, Retry>( &self, op: Operation<O, Retry> ) -> Result<T, SdkError<E>>where O: Send + Sync, E: Error + Send + Sync + 'static, Retry: Send + Sync + ClassifyRetry<SdkSuccess<T>, SdkError<E>>, R::Policy: SmithyRetryPolicy<O, T, E, Retry>, Parsed<<M as SmithyMiddleware<C>>::Service, O, Retry>: Service<Operation<O, Retry>, Response = SdkSuccess<T>, Error = SdkError<E>> + Clone,
Dispatch this request to the network
For ergonomics, this does not include the raw response for successful responses. To
access the raw response use call_raw
.
sourcepub async fn call_raw<O, T, E, Retry>(
&self,
op: Operation<O, Retry>
) -> Result<SdkSuccess<T>, SdkError<E>>where
O: Send + Sync,
E: Error + Send + Sync + 'static,
Retry: Send + Sync + ClassifyRetry<SdkSuccess<T>, SdkError<E>>,
R::Policy: SmithyRetryPolicy<O, T, E, Retry>,
Parsed<<M as SmithyMiddleware<C>>::Service, O, Retry>: Service<Operation<O, Retry>, Response = SdkSuccess<T>, Error = SdkError<E>> + Clone,
pub async fn call_raw<O, T, E, Retry>( &self, op: Operation<O, Retry> ) -> Result<SdkSuccess<T>, SdkError<E>>where O: Send + Sync, E: Error + Send + Sync + 'static, Retry: Send + Sync + ClassifyRetry<SdkSuccess<T>, SdkError<E>>, R::Policy: SmithyRetryPolicy<O, T, E, Retry>, Parsed<<M as SmithyMiddleware<C>>::Service, O, Retry>: Service<Operation<O, Retry>, Response = SdkSuccess<T>, Error = SdkError<E>> + Clone,
Dispatch this request to the network
The returned result contains the raw HTTP response which can be useful for debugging or implementing unsupported features.