Struct actix_web::client::ClientRequest [−][src]
pub struct ClientRequest { /* fields omitted */ }
Expand description
An HTTP Client request builder
This type can be used to construct an instance of ClientRequest
through a
builder-like pattern.
use actix_rt::System;
#[actix_rt::main]
async fn main() {
let response = awc::Client::new()
.get("http://www.rust-lang.org") // <- Create request builder
.header("User-Agent", "Actix-web")
.send() // <- Send http request
.await;
response.and_then(|response| { // <- server http response
println!("Response: {:?}", response);
Ok(())
});
}
Implementations
Set HTTP URI of request.
Set socket address of the server.
This address is used for connection. If address is not provided url’s host name get resolved.
Set HTTP method of this request.
Get HTTP method of this request
Get HTTP version of this request.
Get peer address of this request.
Returns request’s mutable headers.
Set a header.
fn main() {
let req = awc::Client::new()
.get("http://www.rust-lang.org")
.set(awc::http::header::Date::now())
.set(awc::http::header::ContentType(mime::TEXT_HTML));
}
pub fn header<K, V>(self, key: K, value: V) -> ClientRequest where
V: IntoHeaderValue,
HeaderName: TryFrom<K>,
<HeaderName as TryFrom<K>>::Error: Into<Error>,
pub fn header<K, V>(self, key: K, value: V) -> ClientRequest where
V: IntoHeaderValue,
HeaderName: TryFrom<K>,
<HeaderName as TryFrom<K>>::Error: Into<Error>,
Append a header.
Header gets appended to existing header.
To override header use set_header()
method.
use awc::{http, Client};
fn main() {
let req = Client::new()
.get("http://www.rust-lang.org")
.header("X-TEST", "value")
.header(http::header::CONTENT_TYPE, "application/json");
}
pub fn set_header<K, V>(self, key: K, value: V) -> ClientRequest where
V: IntoHeaderValue,
HeaderName: TryFrom<K>,
<HeaderName as TryFrom<K>>::Error: Into<Error>,
pub fn set_header<K, V>(self, key: K, value: V) -> ClientRequest where
V: IntoHeaderValue,
HeaderName: TryFrom<K>,
<HeaderName as TryFrom<K>>::Error: Into<Error>,
Insert a header, replaces existing header.
pub fn set_header_if_none<K, V>(self, key: K, value: V) -> ClientRequest where
V: IntoHeaderValue,
HeaderName: TryFrom<K>,
<HeaderName as TryFrom<K>>::Error: Into<Error>,
pub fn set_header_if_none<K, V>(self, key: K, value: V) -> ClientRequest where
V: IntoHeaderValue,
HeaderName: TryFrom<K>,
<HeaderName as TryFrom<K>>::Error: Into<Error>,
Insert a header only if it is not yet set.
Send headers in Camel-Case
form.
Force close connection instead of returning it back to connections pool. This setting affect only http/1 connections.
pub fn content_type<V>(self, value: V) -> ClientRequest where
HeaderValue: TryFrom<V>,
<HeaderValue as TryFrom<V>>::Error: Into<Error>,
pub fn content_type<V>(self, value: V) -> ClientRequest where
HeaderValue: TryFrom<V>,
<HeaderValue as TryFrom<V>>::Error: Into<Error>,
Set request’s content type
Set content length
pub fn basic_auth<U>(self, username: U, password: Option<&str>) -> ClientRequest where
U: Display,
pub fn basic_auth<U>(self, username: U, password: Option<&str>) -> ClientRequest where
U: Display,
Set HTTP basic authorization header
Set HTTP bearer authentication header
Set a cookie
#[actix_rt::main]
async fn main() {
let resp = awc::Client::new().get("https://www.rust-lang.org")
.cookie(
awc::http::Cookie::build("name", "value")
.domain("www.rust-lang.org")
.path("/")
.secure(true)
.http_only(true)
.finish(),
)
.send()
.await;
println!("Response: {:?}", resp);
}
Disable automatic decompress of response’s body
Set request timeout. Overrides client wide timeout setting.
Request timeout is the total time before a response must be received. Default value is 5 seconds.
Sets the query part of the request
Freeze request builder and construct FrozenClientRequest
,
which could be used for sending same request multiple times.
Complete request construction and send body.
Set a JSON body and generate ClientRequest
Set a urlencoded body and generate ClientRequest
ClientRequestBuilder
can not be used after this call.
pub fn send_stream<S, E>(self, stream: S) -> SendClientRequest where
S: 'static + Stream<Item = Result<Bytes, E>> + Unpin,
E: 'static + Into<Error>,
pub fn send_stream<S, E>(self, stream: S) -> SendClientRequest where
S: 'static + Stream<Item = Result<Bytes, E>> + Unpin,
E: 'static + Into<Error>,
Set an streaming body and generate ClientRequest
.
Set an empty body and generate ClientRequest
.
Trait Implementations
Auto Trait Implementations
impl !RefUnwindSafe for ClientRequest
impl !Send for ClientRequest
impl !Sync for ClientRequest
impl Unpin for ClientRequest
impl !UnwindSafe for ClientRequest
Blanket Implementations
Mutably borrows from an owned value. Read more
Instruments this type with the provided Span
, returning an
Instrumented
wrapper. Read more
Instruments this type with the provided Span
, returning an
Instrumented
wrapper. Read more
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more