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

pub struct Request { /* fields omitted */ }

Request is the entry point for all fetch requests. Its methods configure the request, and handle the response. Many of them return the original struct, and are intended to be used chained together.

Methods

impl Request[src]

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

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

Set the HTTP method. Default is GET.

https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods

pub fn header(self, name: &str, value: &str) -> Self[src]

Add a single header. String multiple calls to this together to add multiple ones.

https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers

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

pub fn body_json<T: Serialize>(self, body_json: &T) -> Self[src]

Serialize a Rust data structure as JSON; eg the payload in a POST request. Note: If you want to setup Content-Type header automatically, use method send_json.

pub fn send_json<T: Serialize>(self, data: &T) -> Self[src]

Set body to serialized data and set header Content-Type to application/json; charset=utf-8.

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

https://developer.mozilla.org/en-US/docs/Web/API/Request/cache

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

https://developer.mozilla.org/en-US/docs/Web/API/Request/credentials

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

https://developer.mozilla.org/en-US/docs/Web/API/Request/integrity

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

https://developer.mozilla.org/en-US/docs/Web/API/Request/mode

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

https://developer.mozilla.org/en-US/docs/Web/API/Request/redirect

pub fn referrer(self, referrer: String) -> Self[src]

https://developer.mozilla.org/en-US/docs/Web/API/Request/referrer

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

https://developer.mozilla.org/en-US/docs/Web/API/Request/referrerPolicy

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

Enable request timeout and set it to given milliseconds.

pub fn controller(
    self,
    controller_transferrer: impl FnOnce(RequestController)
) -> Self
[src]

Get request controller through callback function. You can use controller to abort request or disable timeout.

Example

fn send_request(
   request_controller: &mut Option<fetch::RequestController>
) -> impl Future<Item=Msg, Error=Msg> {
   fetch::Request::new(get_request_url())
       .controller(|controller| *request_controller = Some(controller))
       .fetch_string(Msg::Fetched)
}

pub fn fetch<U>(
    self,
    f: impl FnOnce(FetchObject<()>) -> U
) -> impl Future<Item = U, Error = U> where
    U: 'static, 
[src]

Fetch.

It never fails. Use callback f to map FetchObject<()> to Future Item and Error. E.g.: You can use std::convert::identity as f to return Future<Item=FetchObject<()>, Error=FetchObject<()>>.

It's lazy - fetching is started when Future is executed.

It always set FetchObject.result->ResponseWithDataResult field data to Ok(()) - if you want to get body data, you have to use field raw to get raw web_sys::Response. (Or use methods like fetch_string / fetch_json.)

https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch

Example

fn send_request() -> impl Future<Item=Msg, Error=Msg> {
   fetch::Request::new(get_request_url())
       .fetch(Msg::Fetched)
}

pub fn fetch_string<U>(
    self,
    f: impl FnOnce(FetchObject<String>) -> U
) -> impl Future<Item = U, Error = U> where
    U: 'static, 
[src]

Same as method fetch, but try to convert body to String and insert it into Response field data. https://developer.mozilla.org/en-US/docs/Web/API/Body/text

pub fn fetch_string_data<U>(
    self,
    f: impl FnOnce(ResponseDataResult<String>) -> U
) -> impl Future<Item = U, Error = U> where
    U: 'static, 
[src]

Fetch and then convert body to String. It passes ResponseDataResult<String> into callback f. https://developer.mozilla.org/en-US/docs/Web/API/Body/text

pub fn fetch_json<T, U>(
    self,
    f: impl FnOnce(FetchObject<T>) -> U
) -> impl Future<Item = U, Error = U> where
    T: DeserializeOwned + 'static,
    U: 'static, 
[src]

Same as method fetch, but try to deserialize body and insert it into Response field data.

pub fn fetch_json_data<T, U>(
    self,
    f: impl FnOnce(ResponseDataResult<T>) -> U
) -> impl Future<Item = U, Error = U> where
    T: DeserializeOwned + 'static,
    U: 'static, 
[src]

Fetch and then deserialize body to T. It passes ResponseDataResult<T> into callback f.

Trait Implementations

impl Clone for Request[src]

impl Default for Request[src]

impl Debug for Request[src]

Auto Trait Implementations

impl !Send for Request

impl !Sync for Request

impl Unpin for Request

impl !UnwindSafe for Request

impl !RefUnwindSafe for Request

Blanket Implementations

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

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

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<T> Borrow<T> for T where
    T: ?Sized
[src]

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

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