[][src]Struct attohttpc::RequestBuilder

pub struct RequestBuilder { /* fields omitted */ }

Request is the main way of performing requests.

You can create a RequestBuilder the hard way using the new or try_new method, or use one of the simpler constructors available in the crate root, such as get post, etc.

Methods

impl RequestBuilder[src]

pub fn new<U>(method: Method, base_url: U) -> RequestBuilder where
    U: AsRef<str>, 
[src]

Create a new Request with the base URL and the given method.

Panics

Panics if the base url is invalid or if the method is CONNECT.

pub fn try_new<U>(method: Method, base_url: U) -> Result<RequestBuilder> where
    U: AsRef<str>, 
[src]

Try to create a new RequestBuilder.

If the base URL is invalid, an error is returned. If the method is CONNECT, an error is also returned. CONNECT is not yet supported.

pub fn param<V>(self, key: &str, value: V) -> RequestBuilder where
    V: Display
[src]

Associate a query string parameter to the given value.

The same key can be used multiple times.

pub fn params<'k, 'v, P, V>(self, pairs: P) -> RequestBuilder where
    P: AsRef<[(&'k str, V)]>,
    V: Display + 'v, 
[src]

Associated a list of pairs to query parameters.

The same key can be used multiple times.

pub fn header<H, V>(self, header: H, value: V) -> RequestBuilder where
    H: IntoHeaderName,
    V: HttpTryInto<HeaderValue>, 
[src]

Modify a header for this Request.

If the header is already present, the value will be replaced. If you wish to append a new header, use header_append.

Panics

This method will panic if the value is invalid.

pub fn header_append<H, V>(self, header: H, value: V) -> RequestBuilder where
    H: IntoHeaderName,
    V: HttpTryInto<HeaderValue>, 
[src]

Modify a header for this Request.

If the header is already present, the value will be replaced. If you wish to append a new header, use header_append.

Panics

This method will panic if the value is invalid.

pub fn try_header<H, V>(self, header: H, value: V) -> Result<RequestBuilder> where
    H: IntoHeaderName,
    V: HttpTryInto<HeaderValue>, 
[src]

Modify a header for this Request.

If the header is already present, the value will be replaced. If you wish to append a new header, use header_append.

pub fn try_header_append<H, V>(
    self,
    header: H,
    value: V
) -> Result<RequestBuilder> where
    H: IntoHeaderName,
    V: HttpTryInto<HeaderValue>, 
[src]

Append a new header to this Request.

The new header is always appended to the Request, even if the header already exists.

pub fn text(self, body: impl Into<String>) -> RequestBuilder[src]

Set the body of this request to be text.

If the Content-Type header is unset, it will be set to text/plain and the carset to UTF-8.

pub fn bytes(self, body: impl Into<Vec<u8>>) -> RequestBuilder[src]

Set the body of this request to be bytes.

The can be a &[u8] or a str, anything that's a sequence of bytes. If the Content-Type header is unset, it will be set to application/octet-stream.

pub fn json<T: Serialize>(self, value: &T) -> Result<RequestBuilder>[src]

Set the body of this request to be the JSON representation of the given object.

If the Content-Type header is unset, it will be set to application/json and the charset to UTF-8.

pub fn follow_redirects(self, follow_redirects: bool) -> RequestBuilder[src]

Sets if this Request should follow redirects, 3xx codes.

This value defaults to true.

pub fn default_charset(self, default_charset: Option<Charset>) -> RequestBuilder[src]

Set the default charset to use while parsing the response of this Request.

If the response does not say which charset it uses, this charset will be used to decode the request. This value defaults to None, in which case ISO-8859-1 is used.

pub fn allow_compression(self, allow_compression: bool) -> RequestBuilder[src]

Sets if this Request will announce that it accepts compression.

This value defaults to true. Note that this only lets the browser know that this Request supports compression, the server might choose not to compress the content.

pub fn prepare(self) -> PreparedRequest[src]

Create a PreparedRequest from this RequestBuilder.

Panics

Will panic if an error occurs trying to prepare the request. It shouldn't happen.

pub fn try_prepare(self) -> Result<PreparedRequest>[src]

Create a PreparedRequest from this RequestBuilder.

pub fn send(self) -> Result<Response>[src]

Send this request directly.

Auto Trait Implementations

Blanket Implementations

impl<T, U> Into for T where
    U: From<T>, 
[src]

impl<T> From for T[src]

impl<T, U> TryFrom for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T> Borrow for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> BorrowMut for T where
    T: ?Sized
[src]

impl<T, U> TryInto for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.