Package go.bytecodealliance.org/x/wasihttp implements wasi:http/proxy for Go using standard net/http interfaces.
This package allows Go applications to use the familiar net/http API when building WebAssembly modules that use the WASI HTTP standard.
To use this package, you'll need:
Create a standard Go HTTP server using the familiar net/http API:
package main
import (
"net/http"
_ "go.bytecodealliance.org/x/wasihttp" // enable wasi-http
)
func init() {
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
w.Header().Add("X-Go", "Gopher")
w.Write([]byte("Hello world!\n"))
})
}
func main() {}Compile with:
tinygo build -target=wasip2-http.json -o server.wasm ./main.goFor more examples, see the examples directory.