[−][src]Struct yew::services::fetch::FetchService
A service to fetch resources.
Methods
impl FetchService
[src]
pub fn new() -> Self
[src]
Creates a new service instance connected to App
by provided sender
.
pub fn fetch<IN, OUT: 'static>(
&mut self,
request: Request<IN>,
callback: Callback<Response<OUT>>
) -> FetchTask where
IN: Into<Text>,
OUT: From<Text>,
[src]
&mut self,
request: Request<IN>,
callback: Callback<Response<OUT>>
) -> FetchTask where
IN: Into<Text>,
OUT: From<Text>,
Sends a request to a remote server given a Request object and a callback fuction to convert a Response object into a loop's message.
You may use a Request builder to build your request declaratively as on the following examples:
let post_request = Request::post("https://my.api/v1/resource") .header("Content-Type", "application/json") .body(Json(&json!({"foo": "bar"}))) .expect("Failed to build request."); let get_request = Request::get("https://my.api/v1/resource") .body(Nothing) .expect("Failed to build request.");
The callback function can build a loop message by passing or analizing the response body and metadata.
context.web.fetch( post_request, |response| { if response.status().is_success() { Msg::Noop } else { Msg::Error } } )
One can also simply consume and pass the response or body object into the message.
context.web.fetch( get_request, |response| { let (meta, Json(body)) = response.into_parts(); if meta.status.is_success() { Msg::FetchResourceComplete(body) } else { Msg::FetchResourceFailed } } )
pub fn fetch_with_options<IN, OUT: 'static>(
&mut self,
request: Request<IN>,
options: FetchOptions,
callback: Callback<Response<OUT>>
) -> FetchTask where
IN: Into<Text>,
OUT: From<Text>,
[src]
&mut self,
request: Request<IN>,
options: FetchOptions,
callback: Callback<Response<OUT>>
) -> FetchTask where
IN: Into<Text>,
OUT: From<Text>,
fetch
with provided FetchOptions
object.
Use it if you need to send cookies with a request:
let request = fetch::Request::get("/path/") .body(Nothing).unwrap(); let options = FetchOptions { credentials: Some(Credentials::SameOrigin), ..FetchOptions::default() }; let task = fetch_service.fetch_with_options(request, options, callback);
pub fn fetch_binary<IN, OUT: 'static>(
&mut self,
request: Request<IN>,
callback: Callback<Response<OUT>>
) -> FetchTask where
IN: Into<Binary>,
OUT: From<Binary>,
[src]
&mut self,
request: Request<IN>,
callback: Callback<Response<OUT>>
) -> FetchTask where
IN: Into<Binary>,
OUT: From<Binary>,
Fetch the data in binary format.
pub fn fetch_binary_with_options<IN, OUT: 'static>(
&mut self,
request: Request<IN>,
options: FetchOptions,
callback: Callback<Response<OUT>>
) -> FetchTask where
IN: Into<Binary>,
OUT: From<Binary>,
[src]
&mut self,
request: Request<IN>,
options: FetchOptions,
callback: Callback<Response<OUT>>
) -> FetchTask where
IN: Into<Binary>,
OUT: From<Binary>,
Fetch the data in binary format.
Trait Implementations
impl Default for FetchService
[src]
fn default() -> FetchService
[src]
Auto Trait Implementations
impl Sync for FetchService
impl Send for FetchService
impl Unpin for FetchService
impl UnwindSafe for FetchService
impl RefUnwindSafe for FetchService
Blanket Implementations
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,
impl<T> Any for T where
T: Any,
[src]
T: Any,
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,