Struct generic_async_http_client::Request
source · [−]pub struct Request(_);
Expand description
Builds a HTTP request, poll it to query
Implementations
sourceimpl Request
impl Request
pub fn get(uri: &str) -> Request
pub fn post(uri: &str) -> Request
pub fn put(uri: &str) -> Request
pub fn delete(uri: &str) -> Request
pub fn head(uri: &str) -> Request
pub fn options(uri: &str) -> Request
pub fn new(meth: &str, uri: &str) -> Result<Request, Error>
sourcepub fn json<T: Serialize + ?Sized>(self, json: &T) -> Result<Self, Error>
pub fn json<T: Serialize + ?Sized>(self, json: &T) -> Result<Self, Error>
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
}
sourcepub fn form<T: Serialize + ?Sized>(self, form: &T) -> Result<Self, Error>
pub fn form<T: Serialize + ?Sized>(self, form: &T) -> Result<Self, Error>
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
}
sourcepub fn query<T: Serialize + ?Sized>(self, query: &T) -> Result<Self, Error>
pub fn query<T: Serialize + ?Sized>(self, query: &T) -> Result<Self, Error>
Add query parameter to the request
sourcepub fn set_header<N, V, E1, E2>(self, name: N, value: V) -> Result<Self, Error> where
N: TryInto<HeaderName, Error = E1>,
V: TryInto<HeaderValue, Error = E2>,
Error: From<E1>,
Error: From<E2>,
pub fn set_header<N, V, E1, E2>(self, name: N, value: V) -> Result<Self, Error> where
N: TryInto<HeaderName, Error = E1>,
V: TryInto<HeaderValue, Error = E2>,
Error: From<E1>,
Error: From<E2>,
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
}
sourcepub fn add_header<N, V, E1, E2>(self, name: N, value: V) -> Result<Self, Error> where
N: TryInto<HeaderName, Error = E1>,
V: TryInto<HeaderValue, Error = E2>,
Error: From<E1>,
Error: From<E2>,
pub fn add_header<N, V, E1, E2>(self, name: N, value: V) -> Result<Self, Error> where
N: TryInto<HeaderName, Error = E1>,
V: TryInto<HeaderValue, Error = E2>,
Error: From<E1>,
Error: From<E2>,
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
Trait Implementations
Auto Trait Implementations
impl RefUnwindSafe for Request
impl Send for Request
impl Sync for Request
impl Unpin for Request
impl UnwindSafe for Request
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more