Struct warp::test::RequestBuilder

source ·
pub struct RequestBuilder { /* private fields */ }
Expand description

A request builder for testing filters.

See module documentation for an overview.

Implementations

Sets the method of this builder.

The default if not set is GET.

Example
let req = warp::test::request()
    .method("POST");
Panic

This panics if the passed string is not able to be parsed as a valid Method.

Sets the request path of this builder.

The default is not set is /.

Example
let req = warp::test::request()
    .path("/todos/33");
Panic

This panics if the passed string is not able to be parsed as a valid Uri.

Set a header for this request.

Example
let req = warp::test::request()
    .header("accept", "application/json");
Panic

This panics if the passed strings are not able to be parsed as a valid HeaderName and HeaderValue.

Set the bytes of this request body.

Default is an empty body.

Example
let req = warp::test::request()
    .body("foo=bar&baz=quux");

Set the bytes of this request body by serializing a value into JSON.

Example
let req = warp::test::request()
    .json(&true);

Tries to apply the Filter on this request.

Example
let param = warp::path::param::<u32>();

let ex = warp::test::request()
    .path("/41")
    .filter(&param)
    .unwrap();

assert_eq!(ex, 41);

assert!(
    warp::test::request()
        .path("/foo")
        .filter(&param)
        .is_err()
);

Returns whether the Filter matches this request, or rejects it.

Example
let get = warp::get2();
let post = warp::post2();

assert!(
    warp::test::request()
        .method("GET")
        .matches(&get)
);

assert!(
    !warp::test::request()
        .method("GET")
        .matches(&post)
);

Returns Response provided by applying the Filter.

This requires that the supplied Filter return a Reply.

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.

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.