Skip to content

Make HTTP requests from inside WASM using libcurl.js. Devcontainer.

License

Notifications You must be signed in to change notification settings

wasm-outbound-http-examples/libcurl-js

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Use libcurl.js to send HTTP(s) requests from inside WASM

This devcontainer is configured to provide you an Emscripten and other tools to compile libcurl.js, and run both server-side (websocket-enabled "proxy") and client side (web server to deliever WASM and glue code to browsers).

Open in GitHub Codespaces

The sample code and following instructions are partially based on libcurl.js docs and examples.

Instructions for this devcontainer

Tested with libcurl.js 0.6.11, and Emscripten 3.1.6.

Preparation

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

  2. Clone the libcurl.js repo:

git clone https://github.com/ading2210/libcurl.js --recursive --depth=1

Building and running server-side code

  1. cd to sources of server-side part:
cd libcurl.js/server
  1. Run the server-side part:
./run.sh

This will install dependencies if needed (by using venv) and start a websocket server.

  1. Press Make Public button when codespace shows port forwarding confirmation dialog.

Building browser-side code

  1. Open new terminal tab in your codespace, leaving server-side tab running.

  2. In new tab, cd to sources of client-side part:

cd libcurl.js/client
  1. Compile the client-side code, including patched libcurl:
./build.sh

The compilation will take about 5-10 minutes, resulting to 2.8Mb libcurl.wasm file in the out subfolder, along with 2 glue JS files.

Test with browser

Continue to use terminal tab for client side.

  1. Copy HTTP-request-enabled example from parent folder instead default one:
cp ../../index.html ./
  1. Run simple HTTP server to temporarily publish project to Web:
python3 -m http.server
  1. Codespace will show you "Open in Browser" button. Just click that button or obtain web address from "Forwarded Ports" tab.

  2. As index.html, JS files, and a 2.8M-sized libcurl.wasm are loaded into browser, refer to browser developer console to see the results.

Finish

Perform your own experiments if desired. The worker.html is one of the earliest candidates to try.


Created for (wannabe-awesome) list