A go-wasm library that wraps the Fetch API
go get marwan.io/wasm-fetch
Importing net/http adds ~4 MBs to your wasm binary. If that's an issue for you, you can use this library to make fetch calls.
package main
import (
"context"
"time"
"marwan.io/wasm-fetch"
)
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
defer cancel()
resp, err := fetch.Fetch("/some/api/call", &fetch.Opts{
Body: strings.NewReader(`{"one": "two"}`),
Method: fetch.MethodPost,
Signal: ctx,
})
// use response...
GO-WASM is currently experimental and therefore this package is experimental as well, things can break unexpectedly.