Skip to content

Mocket - Getting Started

Version

A web framework for MoonBit.

Quick Start

bash
moon add oboard/mocket
moonbit
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 js

Native Backend

Set the backend of MoonBit to native in Visual Studio Code

Command: MoonBit: Select Backend -> native

bash
moon run src/example --target native

Then 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").

Released under the Apache 2.0 License.