Created
April 3, 2024 05:22
-
-
Save nilslice/a504f1ebb5cf786ef57f13243fc5857f to your computer and use it in GitHub Desktop.
Supabase Edge Function + Extism
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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