Use Go-Python to send HTTP(s) requests from inside WASM
Instructions for this devcontainer
Tested with Go 1.22.0, Bun 1.0.26, Deno 1.40.4, gpython 23c0aa29.
Preparation
- Open this repo in devcontainer, e.g. using Github Codespaces.
Type or copy/paste following commands to devcontainer's terminal.
Building
cd
into the folder of this example:
cd browser-and-deno
- Clone gpython repo:
git clone --depth=1 https://github.com/go-python/gpython
cd
into the folder of gpython sources:
cd gpython
- Make directory for WASM example,
cd
into it and copy provided code there:
mkdir main
cd main
cp ../../main.go ./
cp ../../*.js ./
cp ../../index.html ./
- Compile the example:
GOOS=js GOARCH=wasm go build -o main.wasm main.go
- Copy the glue JS from Golang distribution to example's folder:
cp "$(go env GOROOT)/misc/wasm/wasm_exec.js" .
Test with browser
- Run simple HTTP server to temporarily publish project to Web:
python3 -m http.server
Codespace will show you "Open in Browser" button. Just click that button or
obtain web address from "Forwarded Ports" tab.
- As
index.html
and a 15.5M-sized main.wasm
are loaded into browser, refer to browser developer console
to see the results.
Test with Node.js
Impossible yet due to https://github.com/golang/go/issues/59605.
Test with Bun
- Install Bun:
curl -fsSL https://bun.sh/install | bash
- Run with Bun:
~/.bun/bin/bun bun.js
Test with Deno
- Install Deno:
curl -fsSL https://deno.land/x/install/install.sh | sh
- Run with Deno:
~/.deno/bin/deno run --allow-read --allow-net deno.js
Finish
Perform your own experiments if desired.