Skip to content

Files

97 lines (62 loc) · 1.65 KB

README.md

File metadata and controls

97 lines (62 loc) · 1.65 KB

Use .Net / C# to send HTTP(s) requests from inside WASM in Node.js, Bun, and Deno

Instructions for this devcontainer

Tested with .Net SDK version 9.0.200, Bun 1.2.4, Deno 2.2.2, Node.js 22.14.0 .

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 workloads to handle WASM:

dotnet workload install wasm-tools
dotnet workload install wasm-experimental

Building

  1. cd into the folder of this example:
cd browser-and-node/node
  1. Create new .Net project using wasmconsole template:
dotnet new wasmconsole -n NodeProject
  1. Replace generated HelloWorld-like Program.cs and main.mjs with HTTP-enabled ones:
cp ../Program.cs ./NodeProject/
cp ../main.js ./NodeProject/main.mjs
  1. cd into the folder of the new .Net project to use it:
cd NodeProject
  1. Compile the example:
dotnet build

Test with Node.js

  1. Run the configuration:
dotnet run

Or, alternatively, the same by directly using node command:

node bin/Debug/net9.0/browser-wasm/AppBundle/main.mjs

Test with Bun

  1. Install Bun:
curl -fsSL https://bun.sh/install | bash
  1. Run with Bun:
~/.bun/bin/bun bin/Debug/net9.0/browser-wasm/AppBundle/main.mjs

Test with Deno

  1. Install Deno:
curl -fsSL https://deno.land/install.sh | bash -s -- --yes
  1. Run with Deno:
~/.deno/bin/deno run --allow-read --allow-net --unstable-bare-node-builtins bin/Debug/net9.0/browser-wasm/AppBundle/main.mjs

Finish

Perform your own experiments if desired.