pub struct RequestBuilder<B = Empty> { /* private fields */ }
Expand description

RequestBuilder is the main way of building requests.

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

Implementations

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

Panics

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

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.

Associate a query string parameter to the given value.

The same key can be used multiple times.

Associated a list of pairs to query parameters.

The same key can be used multiple times.

Example
attohttpc::get("http://foo.bar").params(&[("p1", "v1"), ("p2", "v2")]);

Enable HTTP basic authentication.

Enable HTTP bearer authentication.

Set the body of this request.

The BodyKind enum and Body trait determine how to implement custom request body types.

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 charset to UTF-8.

Set the body of this request to be bytes.

If the Content-Type header is unset, it will be set to application/octet-stream.

Set the body of this request using a local file.

If the Content-Type header is unset, it will be set to application/octet-stream.

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.

Set the body of this request to stream out a 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.

Set the body of this request to be the URL-encoded representation of the given object.

If the Content-Type header is unset, it will be set to application/x-www-form-urlencoded.

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.

Append a new header for this request.

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

Panics

This method will panic if the value is invalid.

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.

Append a new header to this request.

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

Set the maximum number of headers accepted in responses to this request.

The default is 100.

Set the maximum number of redirections this request can perform.

The default is 5.

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

This value defaults to true.

Sets a connect timeout for this request.

The default is 30 seconds.

Sets a read timeout for this request.

The default is 30 seconds.

Sets a timeout for the whole request.

Applies after a TCP connection is established. Defaults to no timeout.

Sets the proxy settigns for this request.

If left untouched, the defaults are to use system proxy settings found in environment variables.

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.

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.

Sets if this request will accept invalid TLS certificates.

Accepting invalid certificates implies that invalid hostnames are accepted as well.

The default value is false.

Danger

Use this setting with care. This will accept any TLS certificate valid or not. If you are using self signed certificates, it is much safer to add their root CA to the list of trusted root CAs by your system.

Sets if this request will accept an invalid hostname in a TLS certificate.

The default value is false.

Danger

Use this setting with care. This will accept TLS certificates that do not match the hostname.

Adds a root certificate that will be trusted.

Create a PreparedRequest from this RequestBuilder.

Panics

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

Create a PreparedRequest from this RequestBuilder.

Send this request directly.

Inspect the properties of this request

Trait Implementations

Formats the value using the given formatter. Read more

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.

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.