pub struct Client(_);Expand description
An asynchronous HTTP and WebSocket client.
You should take care to create, at most, one Client per thread. Otherwise, expect higher CPU
and memory usage.
Examples
use awc::Client;
#[actix_rt::main]
async fn main() {
let mut client = Client::default();
let res = client.get("http://www.rust-lang.org")
.insert_header(("User-Agent", "my-app/1.2"))
.send()
.await;
println!("Response: {:?}", res);
}Implementations
sourceimpl Client
impl Client
sourcepub fn builder(
) -> ClientBuilder<impl Service<ConnectInfo<Uri>, Response = TcpConnection<Uri, TcpStream>, Error = TcpConnectError> + Clone>
pub fn builder(
) -> ClientBuilder<impl Service<ConnectInfo<Uri>, Response = TcpConnection<Uri, TcpStream>, Error = TcpConnectError> + Clone>
Constructs new Client builder.
This function is equivalent of ClientBuilder::new().
sourcepub fn request<U>(&self, method: Method, url: U) -> ClientRequestwhere
Uri: TryFrom<U>,
<Uri as TryFrom<U>>::Error: Into<HttpError>,
pub fn request<U>(&self, method: Method, url: U) -> ClientRequestwhere
Uri: TryFrom<U>,
<Uri as TryFrom<U>>::Error: Into<HttpError>,
Construct HTTP request.
sourcepub fn request_from<U>(&self, url: U, head: &RequestHead) -> ClientRequestwhere
Uri: TryFrom<U>,
<Uri as TryFrom<U>>::Error: Into<HttpError>,
pub fn request_from<U>(&self, url: U, head: &RequestHead) -> ClientRequestwhere
Uri: TryFrom<U>,
<Uri as TryFrom<U>>::Error: Into<HttpError>,
Create ClientRequest from RequestHead
It is useful for proxy requests. This implementation copies all headers and the method.
sourcepub fn get<U>(&self, url: U) -> ClientRequestwhere
Uri: TryFrom<U>,
<Uri as TryFrom<U>>::Error: Into<HttpError>,
pub fn get<U>(&self, url: U) -> ClientRequestwhere
Uri: TryFrom<U>,
<Uri as TryFrom<U>>::Error: Into<HttpError>,
Construct HTTP GET request.
sourcepub fn head<U>(&self, url: U) -> ClientRequestwhere
Uri: TryFrom<U>,
<Uri as TryFrom<U>>::Error: Into<HttpError>,
pub fn head<U>(&self, url: U) -> ClientRequestwhere
Uri: TryFrom<U>,
<Uri as TryFrom<U>>::Error: Into<HttpError>,
Construct HTTP HEAD request.
sourcepub fn put<U>(&self, url: U) -> ClientRequestwhere
Uri: TryFrom<U>,
<Uri as TryFrom<U>>::Error: Into<HttpError>,
pub fn put<U>(&self, url: U) -> ClientRequestwhere
Uri: TryFrom<U>,
<Uri as TryFrom<U>>::Error: Into<HttpError>,
Construct HTTP PUT request.
sourcepub fn post<U>(&self, url: U) -> ClientRequestwhere
Uri: TryFrom<U>,
<Uri as TryFrom<U>>::Error: Into<HttpError>,
pub fn post<U>(&self, url: U) -> ClientRequestwhere
Uri: TryFrom<U>,
<Uri as TryFrom<U>>::Error: Into<HttpError>,
Construct HTTP POST request.
sourcepub fn patch<U>(&self, url: U) -> ClientRequestwhere
Uri: TryFrom<U>,
<Uri as TryFrom<U>>::Error: Into<HttpError>,
pub fn patch<U>(&self, url: U) -> ClientRequestwhere
Uri: TryFrom<U>,
<Uri as TryFrom<U>>::Error: Into<HttpError>,
Construct HTTP PATCH request.
sourcepub fn delete<U>(&self, url: U) -> ClientRequestwhere
Uri: TryFrom<U>,
<Uri as TryFrom<U>>::Error: Into<HttpError>,
pub fn delete<U>(&self, url: U) -> ClientRequestwhere
Uri: TryFrom<U>,
<Uri as TryFrom<U>>::Error: Into<HttpError>,
Construct HTTP DELETE request.
sourcepub fn options<U>(&self, url: U) -> ClientRequestwhere
Uri: TryFrom<U>,
<Uri as TryFrom<U>>::Error: Into<HttpError>,
pub fn options<U>(&self, url: U) -> ClientRequestwhere
Uri: TryFrom<U>,
<Uri as TryFrom<U>>::Error: Into<HttpError>,
Construct HTTP OPTIONS request.
Trait Implementations
Auto Trait Implementations
impl !RefUnwindSafe for Client
impl !Send for Client
impl !Sync for Client
impl Unpin for Client
impl !UnwindSafe for Client
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more