Mocket - Getting Started
A web framework for MoonBit.
Quick Start
bash
moon add oboard/mocketmoonbit
async fn main {
let app = @mocket.new()
app.get("/", _ => "Hello, Mocket!")
app.group("/api", group => {
group.get("/status", _ => ({ "status": "ok" } : Json))
})
app.listen(":4000")
}Mocket supports both js and native backends.
JavaScript Backend
Set the backend of MoonBit to js in Visual Studio Code
Command: MoonBit: Select Backend -> js
bash
moon run src/example --target jsNative Backend
Set the backend of MoonBit to native in Visual Studio Code
Command: MoonBit: Select Backend -> native
bash
moon run src/example --target nativeThen visit http://localhost:4000
TIP
Mocket::serve(port=...) is still available for compatibility, but it is deprecated. New code should use Mocket::listen(address), such as app.listen(":4000").
