Struct restest::request::Request[][src]

pub struct Request<B> where
    B: Serialize
{ /* fields omitted */ }
Expand description

An HTTP request we’re about to run.

Creating a request

First a RequestBuilder must be created. This object will allow to encode the request information. It can be created with Request::get or Request::post, depending on the kind of request needed.

Then, various request metadata can be encoded in the builder once it is created. For instance, one can use the with_header method to specify a header key to the request.

Once the metadata is encoded, the with_body method allows to specify a body and create the final Request object.

The following code snippet shows all these three steps:

use restest::Request;

use serde::Serialize;

let request = Request::get("users")       // Creating the builder...
    .with_header("token", "mom-said-yes") // ... Adding metadata to the builder
    .with_body(GetUsersFilter::All);      // ... Adding a body, building the final Request.

#[derive(Serialize)]
enum GetUsersFilter {
    All,
    YoungerThan(u8),
    OlderThan(u8),
}

Running a request

Once the Request has been successfully created, it can be run by using the Context::run method.

Implementations

Creates a GET request builder for a specific URL.

Specifying an URL

The url argument must be either a string literal or the value produced by the path macro. Only the absolute path to the resource must be passed.

Example
use restest::{path, Request};

let request_1 = Request::get("users");

let user_name = "scrabsha";
let request_2 = Request::get(path!["users", user_name]);

Creates a POST request builder for a specific URL.

Specifying an URL

The url argument must be either a string literal or the value produced by the path macro. Only the absolute path to the resource must be passed.

Refer to the get method documentation for a self-describing example.

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

Performs the conversion.

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

Performs the conversion.

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