Skip to content

Instantly share code, notes, and snippets.

@nilslice
Created April 3, 2024 05:22
Show Gist options
  • Save nilslice/a504f1ebb5cf786ef57f13243fc5857f to your computer and use it in GitHub Desktop.
Save nilslice/a504f1ebb5cf786ef57f13243fc5857f to your computer and use it in GitHub Desktop.
Supabase Edge Function + Extism
import createPlugin from 'https://raw.githubusercontent.com/extism/js-sdk/main/src/mod.ts';
// This could be done inside the server handler too -- but we'll just load one plugin for the exmple
const plugin = await createPlugin(
'https://github.com/extism/plugins/releases/latest/download/count_vowels.wasm',
{ useWasi: true }
);
// call this server with a request like:
// curl -X POST -d '{"input": "this is a test"}' localhost:8000
Deno.serve(async (req) => {
const { input } = await req.json()
// call the plugin's "count_vowels" export function, passing it the `input` fromt the JSON
const out = await plugin.call("count_vowels", input)
return new Response(JSON.stringify(out.json()), { headers: { 'Content-Type': 'application/json' } })
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment