pub struct ClientBuilder<M = Identity> { /* private fields */ }Expand description
An HTTP client builder.
This type configures connectors and middleware before constructing a
Client.
Implementations§
Source§impl ClientBuilder<Identity>
impl ClientBuilder<Identity>
Source§impl<M> ClientBuilder<M>
impl<M> ClientBuilder<M>
Sourcepub fn openssl(self, config: OpensslConnector) -> Self
pub fn openssl(self, config: OpensslConnector) -> Self
Uses an OpenSSL connector for secure connections.
Sourcepub fn rustls(self, config: RustlsClientConfig) -> Self
pub fn rustls(self, config: RustlsClientConfig) -> Self
Uses a rustls connector for secure connections.
Sourcepub fn connector<T>(
self,
f: impl IntoService<T, SharedCfg, TcpConnect<Url>>,
) -> Selfwhere
T: Service<SharedCfg, TcpConnect<Url>, Error = Error<ConnectError>> + 'static,
IoBoxed: From<T::Res>,
pub fn connector<T>(
self,
f: impl IntoService<T, SharedCfg, TcpConnect<Url>>,
) -> Selfwhere
T: Service<SharedCfg, TcpConnect<Url>, Error = Error<ConnectError>> + 'static,
IoBoxed: From<T::Res>,
Uses a custom connector for unsecured connections.
Sourcepub fn secure_connector<T>(
self,
f: impl IntoService<T, SharedCfg, TcpConnect<Url>>,
) -> Selfwhere
T: Service<SharedCfg, TcpConnect<Url>, Error = Error<ConnectError>> + 'static,
IoBoxed: From<T::Res>,
pub fn secure_connector<T>(
self,
f: impl IntoService<T, SharedCfg, TcpConnect<Url>>,
) -> Selfwhere
T: Service<SharedCfg, TcpConnect<Url>, Error = Error<ConnectError>> + 'static,
IoBoxed: From<T::Res>,
Uses a custom connector for secure connections.
Sourcepub fn middleware<U>(self, mw: U) -> ClientBuilder<Stack<U, M>>
pub fn middleware<U>(self, mw: U) -> ClientBuilder<Stack<U, M>>
Applies middleware to the client request service.
Middleware can inspect or modify every request and response.
use ntex::client::{Client, ServiceRequest};
use ntex::service::{fn_layer, cfg::SharedCfg};
#[ntex::main]
async fn main() {
let client = Client::builder()
.middleware(fn_layer(
async move |mut req: ServiceRequest, svc| {
println!("{:?}", req.head().uri);
svc.call(req).await
}
))
.build(SharedCfg::default());
}Sourcepub fn build(self, cfg: impl Into<SharedCfg>) -> Clientwhere
M: Middleware<Sender, SharedCfg>,
M::Service: Service<SharedCfg, ServiceRequest, Res = ServiceResponse, Error = Error<ClientError>> + 'static,
pub fn build(self, cfg: impl Into<SharedCfg>) -> Clientwhere
M: Middleware<Sender, SharedCfg>,
M::Service: Service<SharedCfg, ServiceRequest, Res = ServiceResponse, Error = Error<ClientError>> + 'static,
Builds the Client using the supplied shared configuration.
Add a ClientConfig to SharedCfg to customize client behavior:
use ntex::SharedCfg;
use ntex::client::{Client, ClientConfig};
use ntex::time::Millis;
#[ntex::main]
async fn main() {
let cfg = SharedCfg::new("HTTP-CLIENT")
.add(
ClientConfig::new()
.set_response_timeout(Millis(10_000))
.set_response_payload_limit(1024 * 1024),
)
.build();
let _client = Client::builder().build(cfg);
}Trait Implementations§
Source§impl<M: Debug> Debug for ClientBuilder<M>
impl<M: Debug> Debug for ClientBuilder<M>
Auto Trait Implementations§
impl<M = Identity> !RefUnwindSafe for ClientBuilder<M>
impl<M = Identity> !Send for ClientBuilder<M>
impl<M = Identity> !Sync for ClientBuilder<M>
impl<M = Identity> !UnwindSafe for ClientBuilder<M>
impl<M> Freeze for ClientBuilder<M>where
M: Freeze,
impl<M> Unpin for ClientBuilder<M>where
M: Unpin,
impl<M> UnsafeUnpin for ClientBuilder<M>where
M: UnsafeUnpin,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more