Struct trillium_client::Client
source · pub struct Client { /* private fields */ }
Expand description
A client contains a Config and an optional connection pool and builds conns.
Implementations§
source§impl Client
impl Client
sourcepub fn without_default_header(
self,
name: impl Into<HeaderName<'static>>,
) -> Self
pub fn without_default_header( self, name: impl Into<HeaderName<'static>>, ) -> Self
chainable method to remove a header from default request headers
sourcepub fn with_default_header(
self,
name: impl Into<HeaderName<'static>>,
value: impl Into<HeaderValues>,
) -> Self
pub fn with_default_header( self, name: impl Into<HeaderName<'static>>, value: impl Into<HeaderValues>, ) -> Self
chainable method to insert a new default request header, replacing any existing value
sourcepub fn default_headers(&self) -> &Headers
pub fn default_headers(&self) -> &Headers
borrow the default headers
sourcepub fn default_headers_mut(&mut self) -> &mut Headers
pub fn default_headers_mut(&mut self) -> &mut Headers
borrow the default headers mutably
calling this will copy-on-write if the default headers are shared with another client clone
sourcepub fn with_default_pool(self) -> Self
pub fn with_default_pool(self) -> Self
chainable constructor to enable connection pooling. this can be
combined with [Client::with_config
]
use trillium_smol::ClientConfig;
use trillium_client::Client;
let client = Client::new(ClientConfig::default())
.with_default_pool(); //<-
sourcepub fn build_conn<M>(&self, method: M, url: impl IntoUrl) -> Conn
pub fn build_conn<M>(&self, method: M, url: impl IntoUrl) -> Conn
builds a new conn.
if the client has pooling enabled and there is an available connection to the dns-resolved socket (ip and port), the new conn will reuse that when it is sent.
use trillium_smol::ClientConfig;
use trillium_client::Client;
use trillium_testing::prelude::*;
let client = Client::new(ClientConfig::default());
let conn = client.build_conn("get", "http://trillium.rs"); //<-
assert_eq!(conn.method(), Method::Get);
assert_eq!(conn.url().host_str().unwrap(), "trillium.rs");
sourcepub fn connector(&self) -> &Arc<dyn ObjectSafeConnector>
pub fn connector(&self) -> &Arc<dyn ObjectSafeConnector>
borrow the connector for this client
sourcepub fn clean_up_pool(&self)
pub fn clean_up_pool(&self)
The pool implementation currently accumulates a small memory footprint for each new host. If your application is reusing a pool against a large number of unique hosts, call this method intermittently.
sourcepub fn with_base(self, base: impl IntoUrl) -> Self
pub fn with_base(self, base: impl IntoUrl) -> Self
chainable method to set the base for this client
sourcepub fn build_url(&self, url: impl IntoUrl) -> Result<Url>
pub fn build_url(&self, url: impl IntoUrl) -> Result<Url>
attempt to build a url from this IntoUrl and the Client::base
, if set
sourcepub fn get(&self, url: impl IntoUrl) -> Conn
pub fn get(&self, url: impl IntoUrl) -> Conn
Builds a new client conn with the get http method and the provided url.
let client = Client::new(ClientConfig::default());
let conn = client.get("http://localhost:8080/some/route"); //<-
assert_eq!(conn.method(), Method::Get);
assert_eq!(conn.url().to_string(), "http://localhost:8080/some/route");
sourcepub fn post(&self, url: impl IntoUrl) -> Conn
pub fn post(&self, url: impl IntoUrl) -> Conn
Builds a new client conn with the post http method and the provided url.
let client = Client::new(ClientConfig::default());
let conn = client.post("http://localhost:8080/some/route"); //<-
assert_eq!(conn.method(), Method::Post);
assert_eq!(conn.url().to_string(), "http://localhost:8080/some/route");
sourcepub fn put(&self, url: impl IntoUrl) -> Conn
pub fn put(&self, url: impl IntoUrl) -> Conn
Builds a new client conn with the put http method and the provided url.
let client = Client::new(ClientConfig::default());
let conn = client.put("http://localhost:8080/some/route"); //<-
assert_eq!(conn.method(), Method::Put);
assert_eq!(conn.url().to_string(), "http://localhost:8080/some/route");
sourcepub fn delete(&self, url: impl IntoUrl) -> Conn
pub fn delete(&self, url: impl IntoUrl) -> Conn
Builds a new client conn with the delete http method and the provided url.
let client = Client::new(ClientConfig::default());
let conn = client.delete("http://localhost:8080/some/route"); //<-
assert_eq!(conn.method(), Method::Delete);
assert_eq!(conn.url().to_string(), "http://localhost:8080/some/route");
sourcepub fn patch(&self, url: impl IntoUrl) -> Conn
pub fn patch(&self, url: impl IntoUrl) -> Conn
Builds a new client conn with the patch http method and the provided url.
let client = Client::new(ClientConfig::default());
let conn = client.patch("http://localhost:8080/some/route"); //<-
assert_eq!(conn.method(), Method::Patch);
assert_eq!(conn.url().to_string(), "http://localhost:8080/some/route");
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Client
impl !RefUnwindSafe for Client
impl Send for Client
impl Sync for Client
impl Unpin for Client
impl !UnwindSafe for Client
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
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)