1
0
mirror of https://github.com/taigrr/wasm-experiments synced 2025-01-18 04:03:21 -08:00
2018-05-28 11:41:53 +01:00

834 B

Fetch

The Go http.Transport interface implemented over the WHATWG Fetch API using the WebAssembly arch target.

Usage

This package requires the Go WASM compilation target to be supported. Short example:

c := http.Client{
    Transport: &fetch.Transport{},
}
resp, err := c.Get("https://api.github.com")
if err != nil {
    fmt.Println(err)
    return
}
defer resp.Body.Close()
b, err := ioutil.ReadAll(resp.Body)
if err != nil {
    fmt.Println(err)
    return
}
fmt.Println(string(b))

See my wasm-experiments repo for the full example of its use.

Attribution

The code is largely based on the Fetch API implementation in GopherJS.