pub struct Request(_);
Expand description

Builds a HTTP request, poll it to query

Implementations

Add a JSON body to the request

use generic_async_http_client::{Request, Response, Error};
use serde::Serialize;
#[derive(Serialize)]
struct JoseBody {
    protected: String,
    payload: String,
    signature: String,
}
async fn jose(jose: &JoseBody) -> Result<Response, Error> {
   let req = Request::put("http://example.com/").json(jose)?;
   req.exec().await
}

Add a form data body to the request

use generic_async_http_client::{Request, Response, Error};
use serde::Serialize;
#[derive(Serialize)]
struct ContactForm {
    email: String,
    text: String,
}
async fn post_form(form: &ContactForm) -> Result<Response, Error> {
   let req = Request::post("http://example.com/").form(form)?;
   req.exec().await
}

Add query parameter to the request

Add a body to the request

Add a single header to the request If the map did have this key present, the new value is associated with the key

use generic_async_http_client::{Request, Response, Error};
async fn ua() -> Result<Response, Error> {
   let req = Request::get("http://example.com/").set_header("User-Agent", "generic_async_http_client v0.2")?;
   req.exec().await
}

Add a single header to the request If the map did have this key present, the new value is pushed to the end of the list of values

Send the request to the webserver

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.