Serverless Functions
TypeScript functions that run on Deno, deployed per project. Browsers call them directly (CORS is set per project) and every call carries the caller's verified identity.
The handler
A function's index.ts must have a default export that takes a
Request and returns a
Response (or a promise of one):
export default async (req: Request): Promise<Response> => {
const { args } = await req.json();
return Response.json({ data: { message: "Hello, " + args.name + "!" } });
};
A file with only named exports (export function invite(...)) has nothing to
run: the deploy is refused with
index.ts must use export default (req: Request) => Response; found only named exports: invite.
Errors a handler throws answer the caller 500 {"error":"internal error"}, and
the message is in the function's logs (Studio, or the MCP get_logs tool with
source: "function").
On Excalibase Cloud
Deploy a function from Studio or with the MCP deploy_function tool. Its id
is its address:
POST https://api.excalibase.io/functions/v1/{projectId}/{id}
The caller's token goes in Authorization: Bearer. A function that does not
exist answers 404:
curl -s -X POST "$BASE/functions/v1/$PROJECT_ID/hello" \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{"args": {"name": "World"}}'
# After deploying the handler above with the id "hello":
curl -s -X POST "$BASE/functions/v1/$PROJECT_ID/hello" \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{"args": {"name": "World"}}'
# {"data":{"message":"Hello, World!"}}
From an app, the SDK (@excalibase/sdk 0.13 or later) calls a function by its id. It sends {"args": ...} as
the body and returns data from a {"data": ...} answer:
const hello = await db.functions.hello({ name: "World" });
// POST {url}/functions/v1/{projectId}/hello
// An id may hold one dot, read as module.name:
const links = await db.functions.images.urls({ storageIds });
// POST {url}/functions/v1/{projectId}/images.urls
The deploy and invoke routes shown in the rest of these docs (/deploy, /invoke/{id}, /delete/{id},
/scripts, /stats, /health) are the function runtime's own API, reachable only inside the
cluster or through a port-forward on a self-hosted install. They answer 404 on
api.excalibase.io.
Self-hosting
This section is for running the function runtime yourself. It exposes /deploy and /invoke/{id}
directly; see the Quick Start.
What You Can Build
- Custom APIs — lightweight HTTP handlers without a full backend
- Webhooks — receive and process events from Stripe, GitHub, Slack
- Data transforms — reshape data on the fly
- Browser-callable endpoints — CORS per project, the caller's identity verified
- Provisioning hooks — run scripts before/after database lifecycle events
How It Works
Async is supported. fetch reaches the hosts on your project's outbound
allowlist, plus your project's own API host:
export default async (req: Request): Promise<Response> => {
const { args } = await req.json();
const res = await fetch("https://api.github.com/users/" + args.username);
const user = await res.json();
return Response.json({ data: { name: user.name, repos: user.public_repos } });
};
Functions deploy in ~10ms and invoke in ~1-5ms. Each runs in its own isolated sandbox with no filesystem and no subprocesses. Its network and environment are described in How It Works.
Provisioning Hooks
Edge functions integrate with K8s Provisioning as lifecycle hooks. Attach a function to run before or after database events:
| Hook | When |
|---|---|
post-provision | After a database is ready — seed data, notify Slack, install extensions |
pre-deprovision | Before deletion — create final backup, audit log |
post-backup | After backup completes — notify ops channel |
Hooks are non-blocking. If a function fails, provisioning continues normally.
Get Started
See the Quick Start — deploy your first function in 30 seconds.