[−][src]Struct seed::browser::service::fetch::Request
Please use seed::browser::fetch
module instead
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.
Implementations
impl Request
[src]
pub fn new(url: impl Into<Cow<'static, str>>) -> Self
[src]
Please use seed::browser::fetch
module instead
pub const fn method(self, method: Method) -> Self
[src]
Please use seed::browser::fetch
module instead
Set the HTTP method. Default is GET.
pub fn header(self, name: &str, value: &str) -> Self
[src]
Please use seed::browser::fetch
module instead
Add a single header. String multiple calls to this together to add multiple ones.
pub fn body(self, body: JsValue) -> Self
[src]
Please use seed::browser::fetch
module instead
pub fn body_json<T: Serialize>(self, body_json: &T) -> Self
[src]
Please use seed::browser::fetch
module instead
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]
Please use seed::browser::fetch
module instead
Set body to serialized data
and set header Content-Type
to application/json; charset=utf-8
.
pub fn cache(self, cache: RequestCache) -> Self
[src]
Please use seed::browser::fetch
module instead
pub fn credentials(self, request_credentials: RequestCredentials) -> Self
[src]
Please use seed::browser::fetch
module instead
pub fn integrity(self, integrity: &str) -> Self
[src]
Please use seed::browser::fetch
module instead
pub fn mode(self, mode: RequestMode) -> Self
[src]
Please use seed::browser::fetch
module instead
pub fn redirect(self, redirect: RequestRedirect) -> Self
[src]
Please use seed::browser::fetch
module instead
pub fn referrer(self, referrer: String) -> Self
[src]
Please use seed::browser::fetch
module instead
pub fn referrer_policy(self, referrer_policy: ReferrerPolicy) -> Self
[src]
Please use seed::browser::fetch
module instead
pub fn timeout(self, millis: u32) -> Self
[src]
Please use seed::browser::fetch
module instead
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
Please use seed::browser::fetch
module instead
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) -> U where
U: 'static,
[src]
U: 'static,
Please use seed::browser::fetch
module instead
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
) -> U where
U: 'static,
[src]
self,
f: impl FnOnce(FetchObject<String>) -> U
) -> U where
U: 'static,
Please use seed::browser::fetch
module instead
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 = U> where
U: 'static,
[src]
self,
f: impl FnOnce(ResponseDataResult<String>) -> U
) -> impl Future<Output = U> where
U: 'static,
Please use seed::browser::fetch
module instead
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) -> U where
T: DeserializeOwned + 'static,
U: 'static,
[src]
T: DeserializeOwned + 'static,
U: 'static,
Please use seed::browser::fetch
module instead
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 = U> where
T: DeserializeOwned + 'static,
U: 'static,
[src]
self,
f: impl FnOnce(ResponseDataResult<T>) -> U
) -> impl Future<Output = U> where
T: DeserializeOwned + 'static,
U: 'static,
Please use seed::browser::fetch
module instead
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> Sealed<T> for T where
T: ?Sized,
T: ?Sized,
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>,
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<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,