Skip to content

Make HTTP requests from inside WASM in Extism PDK for .Net . Devcontainer.

License

Notifications You must be signed in to change notification settings

wasm-outbound-http-examples/extism-dotnet-pdk

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Use Extism PDK for .Net to send HTTP(s) requests from inside WASM

This devcontainer is configured to provide you a DotNet SDK 8.0 and wasi-sdk 20.0.

Open in GitHub Codespaces

Instructions for this devcontainer

Preparation

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

  2. Install the WASI workload:

dotnet workload install wasi-experimental
  1. Generate WASI-enabled .Net project:
dotnet new wasiconsole -o HTTPRequestingPlugin
  1. cd into that project's directory:
cd HTTPRequestingPlugin
  1. Add Extism PDK dependency to project:
dotnet add package Extism.Pdk --prerelease
  1. Patch project configuration to produce solid standalone WASM file ( info ):
sed -si.bak 's|<PublishTrimmed>true</PublishTrimmed>|& \n\n<WasmSingleFileBundle>true</WasmSingleFileBundle>\n<WasmBuildNative>true</WasmBuildNative>\n|' HTTPRequestingPlugin.csproj 
  1. Copy HTTP example source code into project's folder to replace generated one:
cp ../Program.cs . 

Building

  1. Compile the example:
dotnet build

Build process creates 25M-sized HTTPRequestingPlugin/bin/Debug/net8.0/wasi-wasm/AppBundle/HTTPRequestingPlugin.wasm bundle.

Test with Extism CLI

For testing purposes, you can invoke functions from Extism plugins with Extism CLI.

  1. Install Extism CLI from Github releases:
wget https://github.com/extism/cli/releases/download/v0.3.0/extism-v0.3.0-linux-amd64.tar.gz
tar -xzf extism-v0.3.0-linux-amd64.tar.gz

And now you have extism binary in current folder.

  1. Run default function (it's _start) from extism plugin with CLI, allowing outbound connections to all hosts:
./extism call ./bin/Debug/net8.0/wasi-wasm/AppBundle/HTTPRequestingPlugin.wasm _start --allow-host '*' --wasi

Finish

Perform your own experiments if desired.


This devcontainer is based on dev-wasm/dev-wasm-dotnet.

Created for (wannabe-awesome) list