[][src]Struct seed::browser::fetch::Request

pub struct Request<'a> { /* fields omitted */ }

Its methods configure the request, and handle the response. Many of them return the original struct, and are intended to be used chained together.

Implementations

impl<'a> Request<'a>[src]

pub fn new(url: impl Into<Cow<'a, str>>) -> Self[src]

Create new request based on the provided url.

To get a Response you need to pass Request to the fetch function.

MDN reference

pub fn headers(self, headers: Headers<'a>) -> Self[src]

Set headers for this request. It will replace any existing headers.

pub fn header(self, header: Header<'a>) -> Self[src]

Set specific header.

pub const fn method(self, method: Method) -> Self[src]

Set HTTP method. Default method is GET.

pub fn body(self, body: JsValue) -> Self[src]

Set request body to provided JsValue. Consider using json or text methods instead.

Panics

This method will panic when request method is GET or HEAD.

pub fn json<T: Serialize + ?Sized>(self, data: &T) -> Result<Self>[src]

Set request body by JSON encoding provided data. It will also set Content-Type header to application/json; charset=utf-8.

Errors

This method can fail if JSON serialization fail. It will then return FetchError::SerdeError.

pub fn text(self, text: impl AsRef<str>) -> Self[src]

Set request body to a provided string. It will also set Content-Type header to text/plain; charset=utf-8.

pub const fn mode(self, mode: RequestMode) -> Self[src]

Set request mode.

MDN reference

pub const fn credentials(self, credentials: RequestCredentials) -> Self[src]

Set request credentials.

MDN reference

pub const fn cache(self, cache: RequestCache) -> Self[src]

Set request cache mode.

MDN reference

pub const fn redirect(self, redirect: RequestRedirect) -> Self[src]

Set request redirect mode.

MDN reference

pub fn referrer(self, referrer: &impl ToString) -> Self[src]

Set request referrer.

MDN reference

pub const fn referrer_policy(self, referrer_policy: ReferrerPolicy) -> Self[src]

Set request referrer policy.

MDN reference

pub fn integrity(self, integrity: &impl ToString) -> Self[src]

Set request subresource integrity.

MDN reference

pub fn timeout(self, timeout: u32) -> Self[src]

Set request timeout in milliseconds.

pub fn controller(self) -> (Self, RequestController)[src]

Get the request controller that allows to abort request or disable request's timeout.

Example

let (request, controller) = Request::new("http://example.com").controller();

pub async fn fetch(self) -> Result<Response>[src]

Fetch request. It's a chainable alternative to fetch(request).

Example

orders.perform_cmd({
    let message = model.new_message.clone();
    async { Msg::Fetched(send_message(message).await) }
});
...
async fn send_message(new_message: String) -> fetch::Result<shared::SendMessageResponseBody> {
    Request::new(get_request_url())
        .method(Method::Post)
        .json(&shared::SendMessageRequestBody { text: new_message })?
        .fetch()
        .await?
        .check_status()?
        .json()
        .await
}

Errors

fetch will return Err only on network errors. This means that even if you get Ok from this function, you still need to check Response status for HTTP errors.

Trait Implementations

impl<'a> Clone for Request<'a>[src]

impl<'a> Debug for Request<'a>[src]

impl<'a> Default for Request<'a>[src]

impl<'a, T: Into<Cow<'a, str>>> From<T> for Request<'a>[src]

impl<'a> From<Url> for Request<'a>[src]

impl<'_> TryFrom<Request<'_>> for Request[src]

type Error = FetchError

The type returned in the event of a conversion error.

Auto Trait Implementations

impl<'a> !RefUnwindSafe for Request<'a>

impl<'a> !Send for Request<'a>

impl<'a> !Sync for Request<'a>

impl<'a> Unpin for Request<'a>

impl<'a> !UnwindSafe for Request<'a>

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> Sealed<T> for T where
    T: ?Sized

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,