Skip to content

"hello world" using Rust and Wasm Components

License

Notifications You must be signed in to change notification settings

bytecodealliance/sample-wasi-http-rust

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

90 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

WASI Rust Sample

Open in GitHub Codespaces

An example project showing how to build an HTTP server for WASI 0.2 built in Rust.

Routes

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

Installation

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

Local Development

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

Working with deployment artifacts

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.

See Also

Hosts

License

Apache-2.0 with LLVM Exception