Struct trillium_proxy::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 with_default_pool(self) -> Client
pub fn with_default_pool(self) -> Client
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, U>(&self, method: M, url: U) -> Connwhere
M: TryInto<Method>,
<M as TryInto<Method>>::Error: Debug,
U: TryInto<Url>,
<U as TryInto<Url>>::Error: Debug,
pub fn build_conn<M, U>(&self, method: M, url: U) -> Connwhere M: TryInto<Method>, <M as TryInto<Method>>::Error: Debug, U: TryInto<Url>, <U as TryInto<Url>>::Error: Debug,
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 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 get<U>(&self, url: U) -> Connwhere
<U as TryInto<Url>>::Error: Debug,
U: TryInto<Url>,
pub fn get<U>(&self, url: U) -> Connwhere <U as TryInto<Url>>::Error: Debug, U: TryInto<Url>,
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<U>(&self, url: U) -> Connwhere
<U as TryInto<Url>>::Error: Debug,
U: TryInto<Url>,
pub fn post<U>(&self, url: U) -> Connwhere <U as TryInto<Url>>::Error: Debug, U: TryInto<Url>,
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<U>(&self, url: U) -> Connwhere
<U as TryInto<Url>>::Error: Debug,
U: TryInto<Url>,
pub fn put<U>(&self, url: U) -> Connwhere <U as TryInto<Url>>::Error: Debug, U: TryInto<Url>,
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<U>(&self, url: U) -> Connwhere
<U as TryInto<Url>>::Error: Debug,
U: TryInto<Url>,
pub fn delete<U>(&self, url: U) -> Connwhere <U as TryInto<Url>>::Error: Debug, U: TryInto<Url>,
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<U>(&self, url: U) -> Connwhere
<U as TryInto<Url>>::Error: Debug,
U: TryInto<Url>,
pub fn patch<U>(&self, url: U) -> Connwhere <U as TryInto<Url>>::Error: Debug, U: TryInto<Url>,
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");