[−][src]Struct seed::fetch::Request
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: String) -> 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]
self,
controller_transferrer: impl FnOnce(RequestController)
) -> Self
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]
self,
f: impl FnOnce(FetchObject<()>) -> U
) -> impl Future<Item = U, Error = U> where
U: 'static,
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]
self,
f: impl FnOnce(FetchObject<String>) -> U
) -> impl Future<Item = U, Error = U> where
U: 'static,
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_json<T, U>(
self,
f: impl FnOnce(FetchObject<T>) -> U
) -> impl Future<Item = U, Error = U> where
T: DeserializeOwned + Debug + 'static,
U: 'static,
[src]
self,
f: impl FnOnce(FetchObject<T>) -> U
) -> impl Future<Item = U, Error = U> where
T: DeserializeOwned + Debug + 'static,
U: 'static,
Same as method fetch
, but try to deserialize body and insert it into Response
field data
.
Trait Implementations
impl Clone for Request
[src]
fn clone(&self) -> Request
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
Performs copy-assignment from source
. Read more
impl Default for Request
[src]
impl Debug for Request
[src]
Auto Trait Implementations
Blanket Implementations
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> From<T> for T
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,