Skip to content

Latest commit

 

History

History
46 lines (30 loc) · 1.08 KB

File metadata and controls

46 lines (30 loc) · 1.08 KB

go.bytecodealliance.org/x/wasihttp

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.

Prerequisites

To use this package, you'll need:

Usage

Server

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.go

Examples

For more examples, see the examples directory.