JavaScript SDK - Edge functions#
Sandboxed JavaScript/TypeScript functions executed server-side.
Create, deploy, invoke#
const { data: fn } = await db.functions.create({
name: 'hello',
runtime: 'javascript', // or 'typescript'
code: `export default (req) => ({ body: { hello: req.body?.name ?? 'world' } });`,
});
const { data: functions } = await db.functions.list();
const { data: one } = await db.functions.get(fn.id);
await db.functions.update(fn.id, { code: '...' });
// Deploy, then invoke
await db.functions.deploy(fn.id);
const { data: result } = await db.functions.invoke(fn.id, {
method: 'POST',
path: '/greet',
headers: { 'x-custom': 'value' },
body: JSON.stringify({ name: 'Asha' }),
});
result.status; // HTTP status returned by the function
await db.functions.remove(fn.id);
TypeScriptTyped results#
const result = await db.functions.invoke<{ body: { hello: string } }>(fn.id, {...});
result.data!.body.hello;
TypeScriptNext: Payments.