[−][src]Struct seed::browser::service::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: impl Into<Cow<'static, str>>) -> Self
[src]
pub const fn method(self, method: Method) -> Self
[src]
Set the HTTP method. Default is GET.
pub fn header(self, name: &str, value: &str) -> Self
[src]
Add a single header. String multiple calls to this together to add multiple ones.
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]
pub fn credentials(self, request_credentials: RequestCredentials) -> Self
[src]
pub fn integrity(self, integrity: &str) -> Self
[src]
pub fn mode(self, mode: RequestMode) -> Self
[src]
pub fn redirect(self, redirect: RequestRedirect) -> Self
[src]
pub fn referrer(self, referrer: String) -> Self
[src]
pub fn referrer_policy(self, referrer_policy: ReferrerPolicy) -> Self
[src]
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 async fn fetch<U>(
self,
f: impl FnOnce(FetchObject<()>) -> U
) -> Result<U, U> where
U: 'static,
[src]
self,
f: impl FnOnce(FetchObject<()>) -> U
) -> Result<U, U> where
U: 'static,
Fetch.
It never fails. Use callback f
to map FetchObject<()>
.
E.g.: You can use std::convert::identity
as f
to return Result<FetchObject<()>, 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
.)
Example
async fn send_request() -> Result<Msg, Msg> { fetch::Request::new(get_request_url()) .fetch(Msg::Fetched) .await }
pub async fn fetch_string<U>(
self,
f: impl FnOnce(FetchObject<String>) -> U
) -> Result<U, U> where
U: 'static,
[src]
self,
f: impl FnOnce(FetchObject<String>) -> U
) -> Result<U, U> where
U: 'static,
Same as method fetch
, but try to convert body to String
and insert it into Response
field data
.
[MDN reference](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<Output = Result<U, U>> where
U: 'static,
[src]
self,
f: impl FnOnce(ResponseDataResult<String>) -> U
) -> impl Future<Output = Result<U, U>> where
U: 'static,
Fetch and then convert body to String
. It passes ResponseDataResult<String>
into callback f
.
MDN reference
pub async fn fetch_json<T, U>(
self,
f: impl FnOnce(FetchObject<T>) -> U
) -> Result<U, U> where
T: DeserializeOwned + 'static,
U: 'static,
[src]
self,
f: impl FnOnce(FetchObject<T>) -> U
) -> Result<U, U> where
T: DeserializeOwned + 'static,
U: 'static,
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<Output = Result<U, U>> where
T: DeserializeOwned + 'static,
U: 'static,
[src]
self,
f: impl FnOnce(ResponseDataResult<T>) -> U
) -> impl Future<Output = Result<U, U>> where
T: DeserializeOwned + 'static,
U: 'static,
Fetch and then deserialize body to T
. It passes ResponseDataResult<T>
into callback f
.
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
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
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> 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>,