http-wasm Guest Library
This library provides a Rust implementation for the Wasm Guest ABI and interfaces with http-wasm.
It is designed for writing Traefik plugins in Rust, and works with any http-wasm compatible runtime.
Design Goals
- Not opinionated, the focus is to provide a very thin wrapper around the host functions.
- Minimal dependency footprint: only the
logcrate is required at runtime. - Low-level
Byteabstraction to enable all use-cases. - Memory-efficient data handling to suit constrained Wasm environments.
Credits
- Initial reference code from http-wasm-rust
- API inspired by http-wasm-guest-tinygo
Usage
Add the dependency to your project:
cargo add http-wasm-guest
Implement the Guest trait and register the plugin. See the examples for complete code.
use ;
Build
Add the WASM target for building the plugin:
rustup target add wasm32-wasip1
Build the library with
cargo build --target wasm32-wasip1 --release
Test
You can run the examples via the provided run.sh script. This creates a running container for the traefik-server with the plugin configured and the whois-service wired into the router.
$ ./run.sh header
[lots of logging output]
$ curl http://whoami.localhost:8080
Hostname: pensive_curran
IP: 127.0.0.1
IP: ::1
RemoteAddr: [::1]:53364
GET / HTTP/1.1
Host: whoami.localhost:8080
User-Agent: curl/8.18.0
Accept: */*
Accept-Encoding: gzip
X-Custom-Header: FooBar
[more output]