Hono-inspired MoonBit web framework with trie routing, middleware, SSE, and mizchi/x HTTP backend for native and Node.js
Dependencies
{
"deps": {
"mizchi/mars": "0.1.0"
}
}async fn main {
let app = @mars.Mars::new()
// Static route
let _ = app.get("/", @mars.handler(async fn(ctx) {
ctx.text("Hello, Mars!")
}))
// Dynamic parameter
let _ = app.get("/users/:id", @mars.handler(async fn(ctx) {
let id = ctx.param("id").unwrap_or("unknown")
ctx.json({ "id": id })
}))
// Wildcard
let _ = app.get("/files/*", @mars.handler(async fn(ctx) {
ctx.text("File path: " + ctx.path())
}))
// Multiple methods
let _ = app.post("/users", @mars.handler(async fn(ctx) {
ctx.json({ "status": "created" }, status=201)
}))
// Start server
app.serve(host="127.0.0.1", port=3000)
}pub(open) trait ExecCtx {
wait_until(Self, async () -> Unit, name~ : String) -> Unit
}pub(all) struct BackgroundTask {
task : async () -> Unit
name : String
}pub(all) struct EmptyEnv {
}pub(all) struct ExecutionContext {
// private fields
}impl ExecCtx for ExecutionContextfn ExecutionContext::wait_until(self : ExecutionContext, task : async () -> Unit, name? : String) -> Unitfn find_char(s : String, c : Char) -> Intfn hex_to_int(c : Char) -> Intfn strip_query_string(path : String) -> Stringfn substring(s : String, start : Int, end : Int) -> Stringfn substring_from(s : String, start : Int) -> Stringfn url_decode(s : String) -> StringHono-inspired MoonBit web framework with trie routing, middleware, SSE, and mizchi/x HTTP backend for native and Node.js
Dependencies