pub struct HttpClient<S, D> { /* private fields */ }Expand description
HTTP client. S = socket (BlockingSocketFactory), D = DNS (DnsResolver).
Clone shares the connection pool (and cookie store when enabled) via Arc.
use barehttp::HttpClient;
let client = HttpClient::new();
let response = client.get("http://example.com").call()?;Implementations§
Source§impl HttpClient<OsBlockingSocket, OsDnsResolver>
impl HttpClient<OsBlockingSocket, OsDnsResolver>
Sourcepub fn with_config(config: Config) -> Self
pub fn with_config(config: Config) -> Self
OS socket + DNS, custom config.
Source§impl<S, D> HttpClient<S, D>where
S: BlockingSocketFactory,
D: DnsResolver,
impl<S, D> HttpClient<S, D>where
S: BlockingSocketFactory,
D: DnsResolver,
Sourcepub fn with_adapters(dns: D, config: Config) -> Self
pub fn with_adapters(dns: D, config: Config) -> Self
Custom DNS + config. Socket type S comes from S::new() at connect time
(HttpClient::<OsBlockingSocket, _>::with_adapters(dns, config)).
Sourcepub fn method(
&self,
method: Method,
url: impl AsRef<str>,
) -> ClientRequestBuilder<S, D>
pub fn method( &self, method: Method, url: impl AsRef<str>, ) -> ClientRequestBuilder<S, D>
Request with an arbitrary method.
Sourcepub fn get(&self, url: impl AsRef<str>) -> ClientRequestBuilder<S, D>
pub fn get(&self, url: impl AsRef<str>) -> ClientRequestBuilder<S, D>
GET (no body).
Sourcepub fn post(&self, url: impl AsRef<str>) -> ClientRequestBuilder<S, D>
pub fn post(&self, url: impl AsRef<str>) -> ClientRequestBuilder<S, D>
POST (body via ClientRequestBuilder::send / ClientRequestBuilder::call).
Sourcepub fn put(&self, url: impl AsRef<str>) -> ClientRequestBuilder<S, D>
pub fn put(&self, url: impl AsRef<str>) -> ClientRequestBuilder<S, D>
PUT (body via ClientRequestBuilder::send / ClientRequestBuilder::call).
Sourcepub fn delete(&self, url: impl AsRef<str>) -> ClientRequestBuilder<S, D>
pub fn delete(&self, url: impl AsRef<str>) -> ClientRequestBuilder<S, D>
DELETE (no request body).
Sourcepub fn head(&self, url: impl AsRef<str>) -> ClientRequestBuilder<S, D>
pub fn head(&self, url: impl AsRef<str>) -> ClientRequestBuilder<S, D>
HEAD (no body).
Sourcepub fn patch(&self, url: impl AsRef<str>) -> ClientRequestBuilder<S, D>
pub fn patch(&self, url: impl AsRef<str>) -> ClientRequestBuilder<S, D>
PATCH (body via ClientRequestBuilder::send / ClientRequestBuilder::call).
Shared cookie store (cookie-jar feature).
Borrow of the store (not Arc); clone the client (or call again) to share
without depending on the internal shared-ownership shape.
Sourcepub fn request(
&self,
method: Method,
url: impl AsRef<str>,
custom_headers: &Headers,
body: Option<impl AsRef<[u8]>>,
) -> Result<Response, Error>
pub fn request( &self, method: Method, url: impl AsRef<str>, custom_headers: &Headers, body: Option<impl AsRef<[u8]>>, ) -> Result<Response, Error>
Redirect loop; each hop connect / write / read.
Body is copied once into an owned buffer (needed for redirect replay).
Pass None::<&[u8]> when there is no body.
§Errors
Error::InvalidRequest for Method::Connect (no tunnel API),
Error::InvalidUrl, Error::Dns, Error::Socket, Error::Parse,
redirect / TLS / size-limit variants, or Error::HttpStatus when configured.
Sourcepub fn request_with_config(
&self,
config: &Config,
method: Method,
url: impl AsRef<str>,
custom_headers: &Headers,
body: Option<impl AsRef<[u8]>>,
) -> Result<Response, Error>
pub fn request_with_config( &self, config: &Config, method: Method, url: impl AsRef<str>, custom_headers: &Headers, body: Option<impl AsRef<[u8]>>, ) -> Result<Response, Error>
Self::request with a caller-supplied config.
Body is copied once into an owned buffer (needed for redirect replay).
Pass None::<&[u8]> when there is no body.
§Errors
Same as Self::request.