Hono-inspired MoonBit web framework with trie routing, middleware, SSE, and mizchi/x HTTP backend for native and Node.js
{
"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 {
fn wait_until(Self, async () -> Unit, name~ : String) -> Unit
}pub(all) struct BackgroundTask {
task : async () -> Unit
name : String
}fn Context::new(request : Request, params : Params, conn : ServerConnection, body_reader : &BinaryReader) -> Contextfn[E : Env, C : ExecCtx] Context::with_env(request : Request, params : Params, conn : ServerConnection, body_reader : &BinaryReader, env : E, exec_ctx : C) -> Contextpub(all) struct EmptyEnv {
}pub(all) struct ExecutionContext {
// private fields
}impl ExecCtx for ExecutionContextfn ExecutionContext::wait_until(self : ExecutionContext, task : async () -> Unit, name? : String) -> Unitpub(all) struct NativeServerLimits {
max_request_head_bytes : Int
max_request_body_bytes : Int
headers_timeout_ms : Int
request_timeout_ms : Int
keep_alive_timeout_ms : Int
max_connections : Int?
}async fn Server::serve(self : Server, host? : String, port? : Int, limits? : NativeServerLimits) -> Unitasync fn[E : Env, C : ExecCtx] Server::serve_with_env(self : Server, host? : String, port? : Int, limits? : NativeServerLimits, env : E, exec_ctx : C) -> Unitfn[E : Env, C : ExecCtx] Server::to_handler_with_env(self : Server, env : E, exec_ctx : C) -> (async (Request, &BinaryReader, ServerConnection) -> Unit)fn 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) -> StringInstall
Download zipHono-inspired MoonBit web framework with trie routing, middleware, SSE, and mizchi/x HTTP backend for native and Node.js