Skip to content

Instantly share code, notes, and snippets.

@saolsen
Created December 20, 2023 21:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save saolsen/294683088bae9a8f9a8cf93e2b392729 to your computer and use it in GitHub Desktop.
Save saolsen/294683088bae9a8f9a8cf93e2b392729 to your computer and use it in GitHub Desktop.
Rust Http Val
[package]
name = "rust_http_val"
version = "0.1.0"
edition = "2018"
[lib]
name="rust_http_val"
path="val.rs"
crate-type = ["cdylib", "rlib"]
[dependencies]
wasm-bindgen = "0.2.84"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0.108"
[profile.release]
lto = true
opt-level = "s"
use serde_json::json;
use wasm_bindgen::prelude::*;
#[wasm_bindgen]
extern "C" {
#[wasm_bindgen(js_namespace = console)]
fn log(s: &str);
}
#[wasm_bindgen]
pub fn handler(method: &str, url: &str, _body: &str) -> Result<String, JsValue> {
log("Handling request from Rust!");
let response = json!({
"message": "Hello from Rust, it works!",
"request": {
"url": url,
"method": method,
}
});
Ok(serde_json::to_string_pretty(&response).unwrap())
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment