Functions
A function is a small wasm program attached to a site and
served on the site’s domain — by default at /_fn/<slug>. Functions run untrusted
on an isolated functions node, separate from your site hosts, with declared
bindings as their only capabilities. Use one to add an API route, a form handler,
or an edge personalization layer next to a WordPress or static site without running a
server.
Reads need functions:read; every mutation needs functions:write.
The function object
Section titled “The function object”| Field | Type | Description |
|---|---|---|
id |
string | Stable identifier, e.g. fn_01J9.... |
site_id |
string | The home site. Functions transfer with it. |
slug |
string | User-facing name; the default route is /_fn/<slug>. |
display_name |
string | Human label. |
language |
string | Guest language: javascript (default), typescript, rust, tinygo, go, c, zig, or swift. |
bindings |
object[] | Declared capabilities — each { kind, name, config }. |
env / secret_refs |
object / string[] | Plain env vars and references to platform-held secrets. |
limits |
object | Per-instance limits (memory, wall-clock, request bytes, rps). |
route_path |
string | Route override; empty means the default /_fn/<slug>. |
build_status |
string | Paste-source build lifecycle: empty, building, deploying, live, or failed. |
active_version_id |
string | The version currently serving. |
last_build_job_id / last_artifact_id |
string | The most recent build job and the wasm artifact it produced. |
created_at / updated_at |
string | RFC 3339 timestamps. |
Bindings
Section titled “Bindings”A function can only touch what it declares:
| Kind | Grants |
|---|---|
kv |
A named key-value store. |
coord |
Coordination primitives (locks, counters). |
fetch |
Outbound HTTP to the configured destination. |
service |
Calls to another function. |
cron bindings are rejected with 400 binding.unsupported — scheduled execution
is a trusted-tier capability, and functions run untrusted by design.
List & retrieve
Section titled “List & retrieve”GET /v1/functions— functions:read every function you own, cursor-paginated.GET /v1/sites/{siteID}/functions— functions:read the per-site view.GET /v1/functions/{functionID}— functions:read one function.
Create a function
Section titled “Create a function”POST /v1/functions
Section titled “POST /v1/functions”functions:write Create a function on one of your
sites. Returns 201 with the function. If you include inline source, the platform
builds it and — with auto_deploy (the default) — deploys it immediately.
| Parameter | Type | Required | Description |
|---|---|---|---|
site_id |
string | yes | The home site — you must be able to manage it. |
slug |
string | yes | Lowercase letters, digits, and hyphens; sets the default route /_fn/<slug>. |
display_name |
string | yes | Human label. |
language |
string | no | Defaults to javascript. An unsupported value returns 400 language.unsupported. |
bindings |
object[] | no | kv, coord, fetch, or service — cron is rejected. |
secret_refs / env |
string[] / object | no | Secrets by reference; plain env vars inline. |
limits |
object | no | Per-instance limits. |
route_path |
string | no | Route override. |
source |
string | no | Inline single-file source, up to 256 KiB — builds (and by default deploys) immediately. |
filename |
string | no | Override the per-language default filename; a bare basename, no path separators. |
auto_deploy |
boolean | no | Default true; false builds only and stages the artifact. |
curl -X POST https://api.managed.dev/v1/functions \ -H "Authorization: Bearer mfk_live_..." \ -H "Content-Type: application/json" \ -d '{ "site_id": "site_01J7...", "slug": "contact-form", "display_name": "Contact form handler", "language": "javascript", "bindings": [{ "kind": "kv", "name": "submissions" }], "source": "export default { async fetch(req, env) { /* … */ return new Response(\"ok\"); } }" }'fn, err := client.Functions.Create(ctx, &forge.FunctionCreateParams{ SiteID: "site_01J7...", Slug: "contact-form", DisplayName: "Contact form handler", Language: "javascript", Source: src, // single-file source, ≤256 KiB})mf functions create --name contact-form --description "Contact form handler"The function then serves at https://acme-store.com/_fn/contact-form.
Build, deploy & roll back
Section titled “Build, deploy & roll back”The three lifecycle mutations each return 202 Accepted with a job reference —
{ "job_id": "job_01J9...", "status": "queued" } — that you track through the
jobs API. Deploys surface as deployment.wasm_deploy jobs,
rollbacks as deployment.wasm_rollback.
POST /v1/functions/{functionID}/build
Section titled “POST /v1/functions/{functionID}/build”functions:write (Re)build the function from pasted
single-file source, or rebuild the stored source when the body is empty. With
auto_deploy (the default) the build rolls out as soon as it succeeds.
| Parameter | Type | Required | Description |
|---|---|---|---|
source |
string | no | New single-file source (≤ 256 KiB); absent rebuilds the stored source. |
filename |
string | no | Per-language filename override. |
auto_deploy |
boolean | no | Default true; false stages the artifact only. |
POST /v1/functions/{functionID}/deploy
Section titled “POST /v1/functions/{functionID}/deploy”functions:write Deploy a prebuilt .wasm artifact —
one you built with auto_deploy: false, or a previous build you’re re-rolling.
| Parameter | Type | Required | Description |
|---|---|---|---|
artifact_id |
string | yes | A built wasm artifact belonging to this function. |
POST /v1/functions/{functionID}/rollback
Section titled “POST /v1/functions/{functionID}/rollback”functions:write Flip the function back to a prior version.
| Parameter | Type | Required | Description |
|---|---|---|---|
version_id |
string | yes | The prior function version to reactivate. |
curl -X POST https://api.managed.dev/v1/functions/fn_01J9.../build \ -H "Authorization: Bearer mfk_live_..."ref, err := client.Functions.Build(ctx, "fn_01J9...", nil) // nil = rebuild the stored sourceif err != nil { return err }_, err = client.Jobs.WaitSuccess(ctx, ref.JobID, nil)mf functions build fn_01J9... --waitDelete a function
Section titled “Delete a function”DELETE /v1/functions/{functionID}
Section titled “DELETE /v1/functions/{functionID}”functions:write Remove the function from the
functions node and delete its record. A missing function returns
404 function.not_found.
Local development with mf fn
Section titled “Local development with mf fn”You don’t need a deploy cycle to iterate. The mf CLI ships a
docker-based local runner that mirrors the platform’s capability tier:
- Install the builder images for your language:
mf fn setup --lang js(alsots,tinygo,rust,c,zig,swift). - Serve a module or source directory locally:
mf fn dev ./contact-form --watch(JavaScript watch loop) — it listens on127.0.0.1:8787by default. - Declare the same bindings you’ll deploy with:
mf fn dev module.wasm --binding kv:submissions --env DEBUG=1 --kv submissions:seed=1. - Run one-shot requests for tests:
mf fn dev module.wasm --once --request req.json. - Build without deploying:
mf fn dev --build ./contact-form --lang tinygo --out fn.wasm.
When it works locally, mf functions build / mf functions deploy ship the same
code to the functions node.