Struct awc::ClientRequest [−][src]
An HTTP Client request builder
This type can be used to construct an instance of ClientRequest
through a
builder-like pattern.
#[actix_rt::main] async fn main() { let response = awc::Client::new() .get("http://www.rust-lang.org") // <- Create request builder .insert_header(("User-Agent", "Actix-web")) .send() // <- Send HTTP request .await; response.and_then(|response| { // <- server HTTP response println!("Response: {:?}", response); Ok(()) }); }
Implementations
impl ClientRequest
[src]
pub fn uri<U>(self, uri: U) -> Self where
Uri: TryFrom<U>,
<Uri as TryFrom<U>>::Error: Into<HttpError>,
[src]
Uri: TryFrom<U>,
<Uri as TryFrom<U>>::Error: Into<HttpError>,
Set HTTP URI of request.
pub fn get_uri(&self) -> &Uri
[src]
Get HTTP URI of request.
pub fn address(self, addr: SocketAddr) -> Self
[src]
Set socket address of the server.
This address is used for connection. If address is not provided url’s host name get resolved.
pub fn method(self, method: Method) -> Self
[src]
Set HTTP method of this request.
pub fn get_method(&self) -> &Method
[src]
Get HTTP method of this request
pub fn get_version(&self) -> &Version
[src]
Get HTTP version of this request.
pub fn get_peer_addr(&self) -> &Option<SocketAddr>
[src]
Get peer address of this request.
pub fn headers(&self) -> &HeaderMap
[src]
Returns request’s headers.
pub fn headers_mut(&mut self) -> &mut HeaderMap
[src]
Returns request’s mutable headers.
pub fn insert_header<H>(self, header: H) -> Self where
H: IntoHeaderPair,
[src]
H: IntoHeaderPair,
Insert a header, replacing any that were set with an equivalent field name.
pub fn insert_header_if_none<H>(self, header: H) -> Self where
H: IntoHeaderPair,
[src]
H: IntoHeaderPair,
Insert a header only if it is not yet set.
pub fn append_header<H>(self, header: H) -> Self where
H: IntoHeaderPair,
[src]
H: IntoHeaderPair,
Append a header, keeping any that were set with an equivalent field name.
use awc::http::header::CONTENT_TYPE; Client::new() .get("http://www.rust-lang.org") .insert_header(("X-TEST", "value")) .insert_header((CONTENT_TYPE, mime::APPLICATION_JSON));
pub fn camel_case(self) -> Self
[src]
Send headers in Camel-Case
form.
pub fn force_close(self) -> Self
[src]
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) -> Self where
HeaderValue: TryFrom<V>,
<HeaderValue as TryFrom<V>>::Error: Into<HttpError>,
[src]
HeaderValue: TryFrom<V>,
<HeaderValue as TryFrom<V>>::Error: Into<HttpError>,
Set request’s content type
pub fn content_length(self, len: u64) -> Self
[src]
Set content length
pub fn basic_auth(self, username: impl Display, password: impl Display) -> Self
[src]
Set HTTP basic authorization header.
If no password is needed, just provide an empty string.
pub fn bearer_auth(self, token: impl Display) -> Self
[src]
Set HTTP bearer authentication header
pub fn cookie(self, cookie: Cookie<'_>) -> Self
[src]
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); }
pub fn no_decompress(self) -> Self
[src]
Disable automatic decompress of response’s body
pub fn timeout(self, timeout: Duration) -> Self
[src]
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.
pub fn query<T: Serialize>(self, query: &T) -> Result<Self, Error>
[src]
Sets the query part of the request
pub fn freeze(self) -> Result<FrozenClientRequest, FreezeRequestError>
[src]
Freeze request builder and construct FrozenClientRequest
,
which could be used for sending same request multiple times.
pub fn send_body<B>(self, body: B) -> SendClientRequestⓘNotable traits for SendClientRequest
impl Future for SendClientRequest type Output = Result<ClientResponse<Decoder<Payload<PayloadStream>>>, SendRequestError>;
where
B: Into<Body>,
[src]
Notable traits for SendClientRequest
impl Future for SendClientRequest type Output = Result<ClientResponse<Decoder<Payload<PayloadStream>>>, SendRequestError>;
B: Into<Body>,
Complete request construction and send body.
pub fn send_json<T: Serialize>(self, value: &T) -> SendClientRequestⓘNotable traits for SendClientRequest
impl Future for SendClientRequest type Output = Result<ClientResponse<Decoder<Payload<PayloadStream>>>, SendRequestError>;
[src]
Notable traits for SendClientRequest
impl Future for SendClientRequest type Output = Result<ClientResponse<Decoder<Payload<PayloadStream>>>, SendRequestError>;
Set a JSON body and generate ClientRequest
pub fn send_form<T: Serialize>(self, value: &T) -> SendClientRequestⓘNotable traits for SendClientRequest
impl Future for SendClientRequest type Output = Result<ClientResponse<Decoder<Payload<PayloadStream>>>, SendRequestError>;
[src]
Notable traits for SendClientRequest
impl Future for SendClientRequest type Output = Result<ClientResponse<Decoder<Payload<PayloadStream>>>, SendRequestError>;
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ⓘNotable traits for SendClientRequest
impl Future for SendClientRequest type Output = Result<ClientResponse<Decoder<Payload<PayloadStream>>>, SendRequestError>;
where
S: Stream<Item = Result<Bytes, E>> + Unpin + 'static,
E: Into<Error> + 'static,
[src]
Notable traits for SendClientRequest
impl Future for SendClientRequest type Output = Result<ClientResponse<Decoder<Payload<PayloadStream>>>, SendRequestError>;
S: Stream<Item = Result<Bytes, E>> + Unpin + 'static,
E: Into<Error> + 'static,
Set an streaming body and generate ClientRequest
.
pub fn send(self) -> SendClientRequestⓘNotable traits for SendClientRequest
impl Future for SendClientRequest type Output = Result<ClientResponse<Decoder<Payload<PayloadStream>>>, SendRequestError>;
[src]
Notable traits for SendClientRequest
impl Future for SendClientRequest type Output = Result<ClientResponse<Decoder<Payload<PayloadStream>>>, SendRequestError>;
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
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T> Instrument for T
[src]
pub fn instrument(self, span: Span) -> Instrumented<Self>
[src]
pub fn in_current_span(self) -> Instrumented<Self>
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> Same<T> for T
type Output = T
Should always be Self
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,