An example project showing how to build an HTTP server for WASI 0.2 built in Rust.
The following HTTP routes are available from the component:
/ # Hello world
/wait # Sleep for one second
/echo # Echo the HTTP body
/echo-headers # Echo the HTTP headers
/echo-trailers # Echo the HTTP trailers
The easiest way to try this project is by opening it in a GitHub Codespace. This will create a VS Code instance with all dependencies installed. If instead you would prefer to run this locally, you can run the following commands:
$ curl https://wasmtime.dev/install.sh -sSf | bash # install wasm runtime
$ cargo install cargo-component # install build tooling
$ cargo install wkg # install wasm OCI tooling
The HTTP server uses the wasi:http/proxy
world. You can run it locally in a
wasmtime
instance by using the following cargo-component command:
$ cargo component serve
This project automatically published compiled Wasm Components as OCI to GitHub
Artifacts. You can pull the artifact with any OCI-compliant tooling and run it
in any Wasm runtime that supports the wasi:http/proxy
world. To fetch the
latest published version from GitHub releases and run it in a local wasmtime
instance you can run the following command:
$ wkg pull ghcr.io/yoshuawuyts/rust-wasi-hello:latest
$ wasmtime serve rust-wasi-hello.wasm
For production workloads however, you may want to use other runtimes or integrations which provide their own OCI integrations. Deployment will vary depending on you providers, though at their core they will tend to be variations on the pull + serve pattern we've shown here.
Hosts
- sample-wasi-http-aks-wasmcloud - A
wasi:http
example host environment running on AKS using the WasmCloud runtime
Apache-2.0 with LLVM Exception