From 438594bb2a1838db7d05ae9fdd37adc3ec2ac492 Mon Sep 17 00:00:00 2001 From: Kjetil Orbekk Date: Thu, 6 Oct 2022 21:22:44 -0400 Subject: Test server communication --- webapp/Cargo.toml | 2 ++ webapp/src/main.rs | 23 +++++++++++++++++++++++ 2 files changed, 25 insertions(+) (limited to 'webapp') diff --git a/webapp/Cargo.toml b/webapp/Cargo.toml index 91fd87c..13a7e6a 100644 --- a/webapp/Cargo.toml +++ b/webapp/Cargo.toml @@ -16,6 +16,8 @@ wee_alloc = "0.4.3" anyhow = "1.0" regex = "1.0" lazy_static = "1.4" +gloo-net = "0.2.4" +wasm-bindgen-futures = "0.4.33" [dev-dependencies] env_logger = "0.8.4" diff --git a/webapp/src/main.rs b/webapp/src/main.rs index 8a1fccc..8b77ea2 100644 --- a/webapp/src/main.rs +++ b/webapp/src/main.rs @@ -5,6 +5,7 @@ pub mod bridge_engine; pub mod card; pub mod components; use components::Game; +use gloo_net::http::Request; extern crate wee_alloc; // Use `wee_alloc` as the global allocator. @@ -19,8 +20,30 @@ fn main() { #[function_component(App)] pub fn app() -> Html { + let msg = use_state(|| "".to_string()); + { + let msg = msg.clone(); + use_effect_with_deps( + move |_| { + wasm_bindgen_futures::spawn_local(async move { + msg.set( + Request::get("/api/test") + .send() + .await + .unwrap() + .json() + .await + .unwrap(), + ) + }); + || () + }, + (), + ) + } html! { <> +

{ &*msg }

-- cgit v1.2.3