pub struct Client(/* private fields */);
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§
source§impl 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) -> ClientRequest
pub fn request<U>(&self, method: Method, url: U) -> ClientRequest
Construct HTTP request.
sourcepub fn request_from<U>(&self, url: U, head: &RequestHead) -> ClientRequest
pub fn request_from<U>(&self, url: U, head: &RequestHead) -> ClientRequest
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) -> ClientRequest
pub fn get<U>(&self, url: U) -> ClientRequest
Construct HTTP GET request.
sourcepub fn head<U>(&self, url: U) -> ClientRequest
pub fn head<U>(&self, url: U) -> ClientRequest
Construct HTTP HEAD request.
sourcepub fn put<U>(&self, url: U) -> ClientRequest
pub fn put<U>(&self, url: U) -> ClientRequest
Construct HTTP PUT request.
sourcepub fn post<U>(&self, url: U) -> ClientRequest
pub fn post<U>(&self, url: U) -> ClientRequest
Construct HTTP POST request.
sourcepub fn patch<U>(&self, url: U) -> ClientRequest
pub fn patch<U>(&self, url: U) -> ClientRequest
Construct HTTP PATCH request.
sourcepub fn delete<U>(&self, url: U) -> ClientRequest
pub fn delete<U>(&self, url: U) -> ClientRequest
Construct HTTP DELETE request.
sourcepub fn options<U>(&self, url: U) -> ClientRequest
pub fn options<U>(&self, url: U) -> ClientRequest
Construct HTTP OPTIONS request.
sourcepub fn ws<U>(&self, url: U) -> WebsocketsRequest
pub fn ws<U>(&self, url: U) -> WebsocketsRequest
Initialize a WebSocket connection. Returns a WebSocket connection builder.
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
Mutably borrows from an owned value. Read more