A full-stack web framework for MoonBit
moon new hello-moonway
cd hello-moonway
# moonway is a server-side framework: switch the project to the native backend
awk '{sub(/preferred_target = "wasm"/, "preferred_target = \"native\"")} 1' moon.mod > moon.mod.tmp && mv moon.mod.tmp moon.mod
moon add daqing/moonway///|
fn main {
let app = @moonway.new()
app.get("/", ctx => ctx.text("Hello, moonway!"))
app.listen(3000)
}moon run cmd/main///|
struct Post {
id : Int
title : String
body : String
}
///|
fn main {
let app = @moonway.new()
let db = @moonway.sqlite("app.db")
db.migrate()
app.get("/posts", ctx => ctx.json(db.all(Post)))
app.post("/posts", ctx => {
let post = ctx.bind(Post)
db.insert(post)
ctx.status(201).json(post)
})
// A ready-to-use admin UI for your data, served at /admin
app.admin("/admin", [Post])
app.listen(3000)
}moonway generate scaffold Post title:string body:stringcreated models/post.mbt
created handlers/posts.mbt
created migrations/001_create_posts.mbt
updated admin registryThe moonway CLI ships with the framework — install it with moon install daqing/moonway.

$ moonway console
moonway 0.1.0 · connected to sqlite://app.db
moonway> Post.count()
42git config core.hooksPath .githookspub struct App {
routes : Array[Route]
middlewares : Array[(Context) -> Context]
cache_policy : CachePolicy[RedisClient]?
ws_routes : Array[WsRoute]
static_dir : String?
}