Struct actix_test::Client
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§
§impl Client
impl Client
pub fn builder(
) -> ClientBuilder<impl Service<ConnectInfo<Uri>, Response = Connection<Uri, TcpStream>, Error = ConnectError> + Clone>
pub fn builder( ) -> ClientBuilder<impl Service<ConnectInfo<Uri>, Response = Connection<Uri, TcpStream>, Error = ConnectError> + Clone>
Constructs new Client
builder.
This function is equivalent of ClientBuilder::new()
.
pub fn request<U>(&self, method: Method, url: U) -> ClientRequest
pub fn request<U>(&self, method: Method, url: U) -> ClientRequest
Construct HTTP request.
pub 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.
pub fn get<U>(&self, url: U) -> ClientRequest
pub fn get<U>(&self, url: U) -> ClientRequest
Construct HTTP GET request.
pub fn head<U>(&self, url: U) -> ClientRequest
pub fn head<U>(&self, url: U) -> ClientRequest
Construct HTTP HEAD request.
pub fn put<U>(&self, url: U) -> ClientRequest
pub fn put<U>(&self, url: U) -> ClientRequest
Construct HTTP PUT request.
pub fn post<U>(&self, url: U) -> ClientRequest
pub fn post<U>(&self, url: U) -> ClientRequest
Construct HTTP POST request.
pub fn patch<U>(&self, url: U) -> ClientRequest
pub fn patch<U>(&self, url: U) -> ClientRequest
Construct HTTP PATCH request.
pub fn delete<U>(&self, url: U) -> ClientRequest
pub fn delete<U>(&self, url: U) -> ClientRequest
Construct HTTP DELETE request.
pub fn options<U>(&self, url: U) -> ClientRequest
pub fn options<U>(&self, url: U) -> ClientRequest
Construct HTTP OPTIONS request.
pub 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