Webhook
Webhook
Section titled “Webhook”Enable the webhook trigger to get a POST endpoint at:
https://microfn.dev/run/{username}/{function}
Minimal function
Section titled “Minimal function”import kv from "@microfn/kv";
// An exported main function is your entrypointexport async function main(input: any) { console.log("processing", input); // const value = await kv.get("my-key"); return "hello " + JSON.stringify(input);}
Useful examples
Section titled “Useful examples”// 1) Echo with basic validationexport async function main(input: any) { if (!input) return { error: "missing input" }; return { ok: true, input };}
// 2) Tiny counter using KVimport kv from "@microfn/kv";
export async function main(input: any) { const key = `hits:${input?.route ?? "default"}`; const hits = (await kv.get<number>(key)) ?? 0; await kv.set(key, hits + 1); return { route: input?.route ?? "default", hits: hits + 1 };}
// 3) Simple HTTP proxy (GET JSON)export async function main(input: any) { const url = input?.url ?? "https://api.github.com/rate_limit"; const res = await fetch(url, { headers: { "User-Agent": "microfn" } }); return await res.json();}
Call it
Section titled “Call it”# String body becomes { "input": "hello" }curl -X POST https://microfn.dev/run/david/test-func -d 'hello'# -> "hello {\"input\":\"hello\"}"
# JSON body is passed through as-iscurl -X POST https://microfn.dev/run/david/test-func -d '{"Hello":"foo"}'# -> "hello {\"Hello\":\"foo\"}"
Input rules
Section titled “Input rules”- JSON object: passed directly to
input
. - String/number: wrapped as
{ "input": value }
.