In yew 0.2 Request::get
worked fine but now yew::services
doesn't exist, how can I make a request to /api/ping
? do I need javascript?
You could try using reqwasm.
For reqwasm 0.4.0:
use reqwasm::http::Request;
Request::get(url)
.send()
.await
.unwrap();
And/or you could use web_sys::{Request, RequestInit}
and wasm_bindgen_futures::JsFuture
.
For web-sys 0.3.55 and wasm-bindgen-futures 0.4.28:
let mut opts = RequestInit::new();
opts.method("GET");
let request = Request::new_with_str_and_init(url, &opts)?;
let window = web_sys::window().unwrap();
JsFuture::from(window.fetch_with_request(&request)).await?;