Struct yew_simple::FetchTask
source · pub struct FetchTask(_);
Expand description
A handle to control sent requests. Can be canceled with a Task::cancel
call.
Implementations
sourceimpl FetchTask
impl FetchTask
sourcepub fn new(
request: Request<Value>,
yew_callback: Callback<Response<String>>
) -> FetchTask
pub fn new(
request: Request<Value>,
yew_callback: Callback<Response<String>>
) -> FetchTask
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:
Examples
use http::Request;
let post_request = Request::post("https://my.api/v1/resource")
.header("Content-Type", "application/json")
.body("Some data".to_string())
.expect("Failed to build request.");
You then attach the callback to the context using context.send_back
.
ⓘ
fn handle_response_initial(response: http::Response<String>) -> Msg {
// Your code here.
}
let callback = context.send_back(handle_response_initial);
Trait Implementations
Auto Trait Implementations
impl RefUnwindSafe for FetchTask
impl Send for FetchTask
impl Sync for FetchTask
impl Unpin for FetchTask
impl UnwindSafe for FetchTask
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more