Struct Client
pub struct Client { /* private fields */ }
A Client to make Requests with.
The Client has various configuration values to tweak, but the defaults
are set to what is usually the most commonly desired value. To configure a
Client, use Client::builder().
The Client holds a connection pool internally, so it is advised that
you create one and reuse it.
Examples
use reqwest::blocking::Client;
#
# fn run() -> Result<(), reqwest::Error> {
let client = Client::new();
let resp = client.get("http://httpbin.org/").send()?;
# drop(resp);
# Ok(())
# }
Implementations
impl Client
fn new() -> ClientConstructs a new
Client.Panic
This method panics if TLS backend cannot be initialized, or the resolver cannot load the system configuration.
Use
Client::builder()if you wish to handle the failure as anErrorinstead of panicking.This method also panics if called from within an async runtime. See docs on [
reqwest::blocking][crate::blocking] for details.fn builder() -> ClientBuilderCreates a
ClientBuilderto configure aClient.This is the same as
ClientBuilder::new().fn get<U: IntoUrl>(&self, url: U) -> RequestBuilderConvenience method to make a
GETrequest to a URL.Errors
This method fails whenever supplied
Urlcannot be parsed.fn post<U: IntoUrl>(&self, url: U) -> RequestBuilderConvenience method to make a
POSTrequest to a URL.Errors
This method fails whenever supplied
Urlcannot be parsed.fn put<U: IntoUrl>(&self, url: U) -> RequestBuilderConvenience method to make a
PUTrequest to a URL.Errors
This method fails whenever supplied
Urlcannot be parsed.fn patch<U: IntoUrl>(&self, url: U) -> RequestBuilderConvenience method to make a
PATCHrequest to a URL.Errors
This method fails whenever supplied
Urlcannot be parsed.fn delete<U: IntoUrl>(&self, url: U) -> RequestBuilderConvenience method to make a
DELETErequest to a URL.Errors
This method fails whenever supplied
Urlcannot be parsed.fn head<U: IntoUrl>(&self, url: U) -> RequestBuilderConvenience method to make a
HEADrequest to a URL.Errors
This method fails whenever supplied
Urlcannot be parsed.fn request<U: IntoUrl>(&self, method: Method, url: U) -> RequestBuilderStart building a
Requestwith theMethodandUrl.Returns a
RequestBuilder, which will allow setting headers and request body before sending.Errors
This method fails whenever supplied
Urlcannot be parsed.fn execute(&self, request: Request) -> Result<Response>Executes a
Request.A
Requestcan be built manually withRequest::new()or obtained from a RequestBuilder withRequestBuilder::build().You should prefer to use the
RequestBuilderandRequestBuilder::send().Errors
This method fails if there was an error while sending request, or redirect limit was exhausted.
Trait Implementations
impl Clone for Client
fn clone(&self) -> Self
impl Debug for Client
fn fmt(&self, f: &mut Formatter<'_>) -> Result
impl Default for Client
fn default() -> Self