pub struct ClientRequestBuilder { /* private fields */ }
Expand description

An HTTP Client request builder

This type can be used to construct an instance of ClientRequest through a builder-like pattern.

Implementations

Set HTTP URI of request.

Set HTTP method of this request.

Set HTTP method of this request.

Set HTTP version of this request.

By default requests’s HTTP version depends on network stream

Append a header.

Header gets appended to existing header. To override header use set_header() method.

use http::header;

fn main() {
    let req = ClientRequest::build()
        .header("X-TEST", "value")
        .header(header::CONTENT_TYPE, "application/json")
        .finish()
        .unwrap();
}

Set a header.

Set a header only if it is not yet set.

Set content encoding.

By default ContentEncoding::Identity is used.

Enables automatic chunked transfer encoding

Enable connection upgrade

Set request’s content type

Set content length

Set a cookie

use actix_web::{client, http};

fn main() {
    let req = client::ClientRequest::build()
        .cookie(
            http::Cookie::build("name", "value")
                .domain("www.rust-lang.org")
                .path("/")
                .secure(true)
                .http_only(true)
                .finish(),
        )
        .finish()
        .unwrap();
}

Do not add default request headers. By default Accept-Encoding and User-Agent headers are set.

Disable automatic decompress response body

Set write buffer capacity

Default buffer capacity is 32kb

Set request timeout

Request timeout is a total time before response should be received. Default value is 5 seconds.

Send request using custom connector

Send request using existing Connection

This method calls provided closure with builder reference if value is true.

This method calls provided closure with builder reference if value is Some.

Set a body and generate ClientRequest.

ClientRequestBuilder can not be used after this call.

Set a JSON body and generate ClientRequest

ClientRequestBuilder can not be used after this call.

Set a urlencoded body and generate ClientRequest

ClientRequestBuilder can not be used after this call.

Set a streaming body and generate ClientRequest.

ClientRequestBuilder can not be used after this call.

Set an empty body and generate ClientRequest

ClientRequestBuilder can not be used after this call.

This method construct new ClientRequestBuilder

Trait Implementations

Formats the value using the given formatter. Read more

Create ClientRequestBuilder from HttpRequest

It is useful for proxy requests. This implementation copies all request headers and the method.

Converts to this type from the input type.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Should always be Self
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.