logicaffeine_web/ui/
data_fetch.rs1#[cfg(target_arch = "wasm32")]
9pub async fn fetch_static_text(path: &str) -> Result<String, String> {
10 let response = gloo_net::http::Request::get(path)
11 .send()
12 .await
13 .map_err(|e| format!("fetching {path}: {e}"))?;
14 if !response.ok() {
15 return Err(format!("fetching {path}: HTTP {}", response.status()));
16 }
17 response
18 .text()
19 .await
20 .map_err(|e| format!("reading {path}: {e}"))
21}
22
23#[cfg(target_arch = "wasm32")]
24pub async fn fetch_static_json<T: serde::de::DeserializeOwned>(path: &str) -> Result<T, String> {
25 let text = fetch_static_text(path).await?;
26 serde_json::from_str(&text).map_err(|e| format!("parsing {path}: {e}"))
27}