mlctrez / wasm-fetch

Web Assembly fetch wrapper that avoids importing net/http.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

WASM-FETCH

GoDoc

A go-wasm library that wraps the Fetch API

Install

go get github.com/mlctrez/wasm-fetch

Motivation

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.

Fork

Forked from https://github.com/marwan-at-work/wasm-fetch to allow use in https://github.com/maxence-charriere/go-app. This fork provides implementations for wasm and a stub for !wasm that allows importing and usage into multi-architecture source.

Example

package main

import (
    "context"
    "time"

    "github.com/mlctrez/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...

Status

GO-WASM is currently experimental and therefore this package is experimental as well, things can break unexpectedly.

About

Web Assembly fetch wrapper that avoids importing net/http.

License:MIT License


Languages

Language:Go 100.0%