Hono-inspired HTTP framework for MoonBit
{
"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(@socket.Addr::parse("127.0.0.1:3000"))
}pub(all) struct BackgroundTask {
task : async () -> Unit
name : String
}pub(all) struct Context {
request : Request
params : Params
vars : Variables
execution_ctx : ExecutionContext
// private fields
}pub(all) struct EmptyEnv {
}pub(all) struct ExecutionContext {
// private fields
}fn ExecutionContext::wait_until(self : ExecutionContext, task : async () -> Unit, name? : String) -> Unit