crescent_wasm_demo

A minimal Crescent web server that also builds for the wasm target.

http
server
wasm
example
crescent
moon add bobzhang/crescent_wasm_demo@0.1.0
Download zip
Author
Version
0.1.0
License
Apache-2.0
Last updated
23 days ago
Downloads
3

Dependencies

README

#bobzhang/crescent_wasm_demo

A minimal web server built with Crescent that targets wasm as well as native (supported_targets = "-all+native+wasm").

Routes:

  • GET / — plain text greeting
  • GET /hello/:name — path parameter echo
  • GET /json — JSON response

#Run

moon run wasm_demo/cmd/main --target wasm moon run wasm_demo/cmd/main --target native

#Test

Handlers can be exercised without network I/O via @crescent.test_client:

///|
async test "hello route" {
let client = @test_client.TestClient(@crescent_wasm_demo.make_app())
let res = client.get("/hello/wasm")
inspect(res.body_text(), content="Hello, wasm!")
}

#
make_app

fn make_app() ->
App

Builds the demo application: a few routes and nothing else.

#
run

async fn run(port~ : Int) -> Unit

Serves the demo application on the given port.