1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
use crate::*;
use unwrap::unwrap;
use wasm_bindgen::{JsValue, JsCast};
use web_sys::{Request, RequestInit, Response};
use wasm_bindgen_futures::{JsFuture};
pub async fn async_spwloc_fetch_text(url: String) -> String {
let mut opts = RequestInit::new();
opts.method("GET");
let request = unwrap!(Request::new_with_str_and_init(&url, &opts));
let resp_jsvalue =
unwrap!(JsFuture::from(utilsmod::window().fetch_with_request(&request)).await);
let resp: Response = unwrap!(resp_jsvalue.dyn_into());
let resp_body_text = unwrap!(JsFuture::from(unwrap!(resp.text())).await);
unwrap!(JsValue::as_string(&resp_body_text))
}
pub async fn fetch_response(url: String) -> String {
let mut opts = RequestInit::new();
opts.method("GET");
let request = unwrap!(Request::new_with_str_and_init(&url, &opts));
let resp_jsvalue =
unwrap!(JsFuture::from(utilsmod::window().fetch_with_request(&request)).await);
let resp: Response = unwrap!(resp_jsvalue.dyn_into());
let text_jsvalue = unwrap!(JsFuture::from(unwrap!(resp.text())).await);
let txt_response: String = unwrap!(text_jsvalue.as_string());
txt_response
}
pub async fn fetch_only(url: String) {
let mut opts = RequestInit::new();
opts.method("GET");
let request = unwrap!(Request::new_with_str_and_init(&url, &opts));
unwrap!(JsFuture::from(utilsmod::window().fetch_with_request(&request)).await);
}