https://codeberg.org/lil5/mali_gleam
import js_obj/js_obj.{type Object}
import mali/mali
type HelloRequest {
HelloRequest(name: String)
}
fn decode_hello_request(data: Object) {
let name = js_obj.get(data, "name")
HelloRequest(name:)
}
type HelloReply {
HelloReply(message: String)
}
fn encode_hello_reply(data: HelloReply) -> Object {
js_obj.create()
|> js_obj.set("message", data.message)
}
pub fn main() {
mali.create_app("./helloworld.proto")
|> mali.use_("SayHello", fn(req: Object) {
let req = decode_hello_request(req)
Ok(encode_hello_reply(HelloReply(message: "Hello " <> req.name)))
})
|> mali.start("127.0.0.1:8080")
}
(this doesn't work under erlang)