Struct ntex::http::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 ntex::http::client::Client; #[ntex::main] async fn main() { let response = Client::new() .get("http://www.rust-lang.org") // <- Create request builder .header("User-Agent", "ntex::web") .send() // <- Send http request .await; response.and_then(|response| { // <- server http response println!("Response: {:?}", response); Ok(()) }); }
Implementations
impl ClientRequest
[src]
impl ClientRequest
[src]pub fn uri<U>(self, uri: U) -> Self where
Uri: TryFrom<U>,
<Uri as TryFrom<U>>::Error: Into<HttpError>,
[src]
pub fn uri<U>(self, uri: U) -> Self where
Uri: TryFrom<U>,
<Uri as TryFrom<U>>::Error: Into<HttpError>,
[src]Set HTTP URI of request.
pub fn address(self, addr: SocketAddr) -> Self
[src]
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 get_method(&self) -> &Method
[src]
pub fn get_method(&self) -> &Method
[src]Get HTTP method of this request
pub fn get_version(&self) -> &Version
[src]
pub fn get_version(&self) -> &Version
[src]Get HTTP version of this request.
pub fn headers_mut(&mut self) -> &mut HeaderMap
[src]
pub fn headers_mut(&mut self) -> &mut HeaderMap
[src]Returns request’s mutable headers.
pub fn header<K, V>(self, key: K, value: V) -> Self where
HeaderName: TryFrom<K>,
HeaderValue: TryFrom<V>,
<HeaderName as TryFrom<K>>::Error: Into<HttpError>,
<HeaderValue as TryFrom<V>>::Error: Into<HttpError>,
[src]
pub fn header<K, V>(self, key: K, value: V) -> Self where
HeaderName: TryFrom<K>,
HeaderValue: TryFrom<V>,
<HeaderName as TryFrom<K>>::Error: Into<HttpError>,
<HeaderValue as TryFrom<V>>::Error: Into<HttpError>,
[src]Append a header.
Header gets appended to existing header.
To override header use set_header()
method.
use ntex::http; use ntex::http::client::Client; #[ntex::main] async 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) -> Self where
HeaderName: TryFrom<K>,
HeaderValue: TryFrom<V>,
<HeaderName as TryFrom<K>>::Error: Into<HttpError>,
<HeaderValue as TryFrom<V>>::Error: Into<HttpError>,
[src]
pub fn set_header<K, V>(self, key: K, value: V) -> Self where
HeaderName: TryFrom<K>,
HeaderValue: TryFrom<V>,
<HeaderName as TryFrom<K>>::Error: Into<HttpError>,
<HeaderValue as TryFrom<V>>::Error: Into<HttpError>,
[src]Insert a header, replaces existing header.
pub fn set_header_if_none<K, V>(self, key: K, value: V) -> Self where
HeaderName: TryFrom<K>,
HeaderValue: TryFrom<V>,
<HeaderName as TryFrom<K>>::Error: Into<HttpError>,
<HeaderValue as TryFrom<V>>::Error: Into<HttpError>,
[src]
pub fn set_header_if_none<K, V>(self, key: K, value: V) -> Self where
HeaderName: TryFrom<K>,
HeaderValue: TryFrom<V>,
<HeaderName as TryFrom<K>>::Error: Into<HttpError>,
<HeaderValue as TryFrom<V>>::Error: Into<HttpError>,
[src]Insert a header only if it is not yet set.
pub fn force_close(self) -> Self
[src]
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]
pub fn content_type<V>(self, value: V) -> Self where
HeaderValue: TryFrom<V>,
<HeaderValue as TryFrom<V>>::Error: Into<HttpError>,
[src]Set request’s content type
pub fn content_length(self, len: u64) -> Self
[src]
pub fn content_length(self, len: u64) -> Self
[src]Set content length
pub fn basic_auth<U>(self, username: U, password: Option<&str>) -> Self where
U: Display,
[src]
pub fn basic_auth<U>(self, username: U, password: Option<&str>) -> Self where
U: Display,
[src]Set HTTP basic authorization header
pub fn bearer_auth<T>(self, token: T) -> Self where
T: Display,
[src]
pub fn bearer_auth<T>(self, token: T) -> Self where
T: Display,
[src]Set HTTP bearer authentication header
pub fn cookie(self, cookie: Cookie<'_>) -> Self
[src]
pub fn cookie(self, cookie: Cookie<'_>) -> Self
[src]Set a cookie
use coo_kie as cookie; use ntex::http::client::Client; #[ntex::main] async fn main() { let resp = Client::new().get("https://www.rust-lang.org") .cookie( cookie::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]
pub fn no_decompress(self) -> Self
[src]Disable automatic decompress of response’s body
pub fn timeout(self, timeout: Duration) -> Self
[src]
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 if_true<F>(self, value: bool, f: F) -> Self where
F: FnOnce(ClientRequest) -> ClientRequest,
[src]
pub fn if_true<F>(self, value: bool, f: F) -> Self where
F: FnOnce(ClientRequest) -> ClientRequest,
[src]This method calls provided closure with builder reference if
value is true
.
pub fn if_some<T, F>(self, value: Option<T>, f: F) -> Self where
F: FnOnce(T, ClientRequest) -> ClientRequest,
[src]
pub fn if_some<T, F>(self, value: Option<T>, f: F) -> Self where
F: FnOnce(T, ClientRequest) -> ClientRequest,
[src]This method calls provided closure with builder reference if
value is Some
.
pub fn query<T: Serialize>(self, query: &T) -> Result<Self, Error>
[src]
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]
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, SendRequestError>;
where
B: Into<Body>,
[src]
pub fn send_body<B>(self, body: B) -> SendClientRequestⓘNotable traits for SendClientRequest
impl Future for SendClientRequest type Output = Result<ClientResponse, SendRequestError>;
where
B: Into<Body>,
[src]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, SendRequestError>;
[src]
pub fn send_json<T: Serialize>(self, value: &T) -> SendClientRequestⓘNotable traits for SendClientRequest
impl Future for SendClientRequest type Output = Result<ClientResponse, SendRequestError>;
[src]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, SendRequestError>;
[src]
pub fn send_form<T: Serialize>(self, value: &T) -> SendClientRequestⓘNotable traits for SendClientRequest
impl Future for SendClientRequest type Output = Result<ClientResponse, SendRequestError>;
[src]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, SendRequestError>;
where
S: Stream<Item = Result<Bytes, E>> + Unpin + 'static,
E: Error + 'static,
[src]
pub fn send_stream<S, E>(self, stream: S) -> SendClientRequestⓘNotable traits for SendClientRequest
impl Future for SendClientRequest type Output = Result<ClientResponse, SendRequestError>;
where
S: Stream<Item = Result<Bytes, E>> + Unpin + 'static,
E: Error + 'static,
[src]Set an streaming body and generate ClientRequest
.
pub fn send(self) -> SendClientRequestⓘNotable traits for SendClientRequest
impl Future for SendClientRequest type Output = Result<ClientResponse, SendRequestError>;
[src]
pub fn send(self) -> SendClientRequestⓘNotable traits for SendClientRequest
impl Future for SendClientRequest type Output = Result<ClientResponse, SendRequestError>;
[src]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> BorrowMut<T> for T where
T: ?Sized,
[src]
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]pub fn borrow_mut(&mut self) -> &mut T
[src]
pub fn borrow_mut(&mut self) -> &mut T
[src]Mutably borrows from an owned value. Read more
impl<T> Instrument for T
[src]
impl<T> Instrument for T
[src]fn instrument(self, span: Span) -> Instrumented<Self>
[src]
fn instrument(self, span: Span) -> Instrumented<Self>
[src]Instruments this type with the provided Span
, returning an
Instrumented
wrapper. Read more
fn in_current_span(self) -> Instrumented<Self>
[src]
fn in_current_span(self) -> Instrumented<Self>
[src]impl<T> Same<T> for T
impl<T> Same<T> for T
type Output = T
type Output = T
Should always be Self