diff options
| author | LLLL Colonq <llll@colonq> | 2024-03-03 00:10:10 -0500 |
|---|---|---|
| committer | LLLL Colonq <llll@colonq> | 2024-03-03 00:10:10 -0500 |
| commit | 070108cf09b1b561613b6eea04723afbbb464507 (patch) | |
| tree | 01503df63f16ef6ef4ab4a37b24305286bb2477c /src/request.rs | |
Initial commit (new winit)
Diffstat (limited to 'src/request.rs')
| -rw-r--r-- | src/request.rs | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/src/request.rs b/src/request.rs new file mode 100644 index 0000000..7f66f57 --- /dev/null +++ b/src/request.rs @@ -0,0 +1,20 @@ +use wasm_bindgen::JsCast; + +pub async fn get_store(key: &str) -> Option<String> { + let mut opts = web_sys::RequestInit::new(); + opts.method("GET"); + opts.mode(web_sys::RequestMode::Cors); + + let url = format!("https://colonq.computer/bullfrog/api/get/{}", key); + + let request = web_sys::Request::new_with_str_and_init(&url, &opts).ok()?; + + let window = web_sys::window().unwrap(); + let resp_value = wasm_bindgen_futures::JsFuture::from(window.fetch_with_request(&request)).await.ok()?; + + assert!(resp_value.is_instance_of::<web_sys::Response>()); + let resp: web_sys::Response = resp_value.dyn_into().unwrap(); + + let text = wasm_bindgen_futures::JsFuture::from(resp.text().ok()?).await.ok()?; + text.as_string() +} |
