A wazero host module, ABI and guest SDK enabling WASI modules to register as HTTP servers.
First register the host module with the runtime
import (
"context"
_ "embed"
"net"
"net/http"
"github.com/tetratelabs/wazero"
"github.com/tetratelabs/wazero/imports/wasi_snapshot_preview1"
"github.com/pantopic/wazero-pool"
"github.com/pantopic/ext-http-server/host-wazero"
)
//go:embed test\.wasm
var wasm []byte
func main() {
ctx := context.Background()
runtime := wazero.NewRuntimeWithConfig(ctx, wazero.NewRuntimeConfig())
wasi_snapshot_preview1.MustInstantiate(ctx, runtime)
hostModule := wazero_http_server.New()
hostModule.Register(ctx, runtime)
httpServer := http.NewServer()
pool, err := wazeropool.New(ctx, runtime, wasm)
if err != nil {
panic(err)
}
hostModule.RegisterServices(ctx, httpServer, pool)
httpListener, _ := net.Listen(`tcp`, `:8000`)
httpServer.Serve(httpListener)
// ...
}This project is in alpha. Breaking API changes should be expected until Beta.
v0.0.x- Alpha- Stabilize API
v0.x.x- Beta- Finalize API
- Test in production
v1.x.x- General Availability- Proven long term stability in production