pub struct RequestBuilder { /* private fields */ }
Available on crate feature test only.
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.

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
TestClient::get("http://foo.bar").queries(&[("p1", "v1"), ("p2", "v2")]);

Enable HTTP basic authentication.

Enable HTTP bearer authentication.

Sets the body of this request.

Sets 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.

Sets the body of this request to be bytes.

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

Sets 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.

Sets the body of this request to be the JSON representation of the given string.

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

Sets 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.

Sets the body of this request to be the URL-encoded representation of the given string.

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

Modify a header for this response.

When overwrite is set to true, If the header is already present, the value will be replaced. When overwrite is set to false, The new header is always appended to the request, even if the header already exists.

Build final request.

Build hyper request.

Send request to target, such as Router, Service, Handler.

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.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Instruments this type with the current Span, returning an Instrumented wrapper. Read more

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.
Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more