Skip to content

Webhook

Enable the webhook trigger to get a POST endpoint at:

https://microfn.dev/run/{username}/{function}
import kv from "@microfn/kv";
// An exported main function is your entrypoint
export async function main(input: any) {
console.log("processing", input);
// const value = await kv.get("my-key");
return "hello " + JSON.stringify(input);
}
// 1) Echo with basic validation
export async function main(input: any) {
if (!input) return { error: "missing input" };
return { ok: true, input };
}
// 2) Tiny counter using KV
import 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();
}
Terminal window
# 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-is
curl -X POST https://microfn.dev/run/david/test-func -d '{"Hello":"foo"}'
# -> "hello {\"Hello\":\"foo\"}"
  • JSON object: passed directly to input.
  • String/number: wrapped as { "input": value }.