Skip to content

Latest commit

 

History

History
76 lines (49 loc) · 1.62 KB

File metadata and controls

76 lines (49 loc) · 1.62 KB

Use .Net's System.Net.Http.HttpClient to send HTTP(s) requests from inside WASM in WASI Preview 2 environment

Instructions for this devcontainer

Tested with .Net SDK version 10.0.102, official WASIp2 example tagged v10.0.2, Wasmtime v41.0.1.

Preparation

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

  2. Install .Net workload to handle WASI:

dotnet workload install wasi-experimental

Building

  1. cd into the folder of this example:
cd wasip2-http
  1. Create new .Net project using wasiconsole template:
dotnet new wasiconsole -n Wasip2-Http
  1. cd into the folder of the new .Net project to use it:
cd Wasip2-Http
  1. Replace generated HelloWorld-like Program.cs with downloaded official http-p2 example:
rm Program.cs
wget https://github.com/dotnet/runtime/raw/refs/tags/v10.0.2/src/mono/sample/wasi/http-p2/Program.cs
  1. Compile the example:
dotnet build -c Release

Test with Wasmtime

  1. Install Wasmtime:
curl https://wasmtime.dev/install.sh -sSf | bash
  1. cd into the folder of just-compiled binaries bundle:
cd bin/*/net*/wasi-wasm/AppBundle
  1. Run Wasmtime with HTTP plugin enabled against just-compiled HTTP Client example:
~/.wasmtime/bin/wasmtime run --dir . -S http dotnet.wasm Wasip2-Http
  1. See the results in terminal.

Finish

Perform your own experiments if desired.