I'm using wasm_bindgen built with wasm-pack. I have a Rust function I expose to JS:
#[wasm_bindgen]
pub async fn validate_registration_token(backend_api_domain: String, token: String) -> Result<JsValue, JsValue> {
console::log_1(&"backend_api_domain=".clone().into());
console::log_1(&backend_api_domain.clone().into());
console::log_1(&"token=".clone().into());
console::log_1(&backend_api_domain.clone().into());
let api_endpoint_get_guest_info = format!(
"{backend_api_domain}/weddings/{token}/guests/registration/{registration_token}",
backend_api_domain = backend_api_domain.clone(),
token = token.clone(),
registration_token = registration_token.clone()
);
console::log_1(&api_endpoint_get_guest_info.clone().into());
let res = reqwest::Client::new()
.get(&api_endpoint_get_guest_info)
.send()
.await
.unwrap();
let text = res.text().await.unwrap();
let promise = js_sys::Promise::resolve(&true.into());
let result = wasm_bindgen_futures::JsFuture::from(promise).await.unwrap();
Ok(result)
}
Run Code Online (Sandbox Code Playgroud)
In HTML / JavaScript, I call the Rust function:
<button
type="button" …Run Code Online (Sandbox Code Playgroud)