soma.cell

HTTP server

HTTP server, in the reference of the Soma programming language (soma 3.2.4). A block marked ✓ is a whole program that soma check accepts; the others are excerpts.

// Run: soma serve app.cell
// HTTP on :8080 (127.0.0.1 unless --host); WS on :8081 only with `on ws`;
// signal bus on :8082 only with emit / scale / --join
// Dashboard: http://localhost:8080/__soma/ (state machines, budget, verification)

on request(method: String, path: String, body: String) {
    match path {
        "/"         -> html(render_page())
        "/api/data" -> get_all_data()
        _           -> response(404, map("error", "not found"))
    }
}

// Response types:
html("<h1>Hello</h1>")                // text/html
map("key", "value")                    // application/json (auto)
response(201, map("id", 1))           // custom status code
redirect("/other")                     // 302 redirect
sse("trade", "update")                // SSE event stream