Skip to content

Latest commit

 

History

History
75 lines (48 loc) · 1.84 KB

README.md

File metadata and controls

75 lines (48 loc) · 1.84 KB

Use quad-net plugin for Miniquad to send HTTP(s) requests from inside WASM

Instructions for this devcontainer

This demo uses (slightly patched) code from official quad-net example.

Tested with Rust 1.82.0, quad-net commit 31796d4ed.

Preparation

  1. Open this repo in devcontainer, e.g. using Github Codespaces. Type or copy/paste following commands to devcontainer's terminal.

Building

  1. cd into the folder of this example:
cd browser-quad-net
  1. Clone the quad-net repo:
git clone --depth=1 https://github.com/not-fl3/quad-net.git
  1. cd into the cloned repo:
cd quad-net
  1. Patch the provided example to make a HTTP request to remote website:
sed -i.bak 's|http://127.0.0.1:4000/|https://httpbin.org/anything|' examples/http_request.rs
sed -i.bak 's|client.wasm|http_request.wasm|' examples/web/index.html
  1. Compile the example:
cargo build --example http_request --target wasm32-unknown-unknown --release
  1. Copy the built WASM file to example's web folder:
cp target/wasm32-unknown-unknown/release/examples/http_request.wasm examples/web/
  1. Copy the demo's file into current folder:
cp ../index.html ./

Test with browser

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

  1. As HTML, JS files, and a 450k-sized WASM file are loaded into browser, press a "HTTP Request" button and refer to browser developer console to see the results.

Finish

Perform your own experiments if desired.