Declare endpoints, auth, subscriptions and schedules
Everything a function needs is declared in its code. The platform reads the declarations from the built artifact when you publish; there is no separate manifest to keep in step. The result is the function’s describe document (field-by-field in Function describe document and ABI). If the code does not declare it, the runner will not let the function do it.
Declarations in the four languages
Section titled “Declarations in the four languages”var greeting = fn.Config("GREETING")var orders = fn.DB("main")
func init() { fn.Webhook("POST /events/order-created", onOrderCreated, fn.Timeout(10*time.Second), fn.MaxBody(256<<10)) fn.Platform("GET /orders/{id}", getOrder) fn.Open("GET /healthz", health)
fn.Subscribe("shop:orders:order:created", "/events/order-created", fn.Mode("IMMEDIATE")) fn.Schedule("0 */15 * * * *", "/events/order-created", fn.Timezone("Africa/Johannesburg")) fn.HTTPAllow("api.stripe.com") fn.Emits("shop:orders:order:invoiced")}
func main() {}Handlers are plain net/http handlers. Endpoint options: fn.Timeout, fn.MaxBody, fn.CORS.
Subscription options: fn.Mode, fn.MaxRetries, fn.DataOnly, fn.SubTimeout. Schedule options:
fn.Timezone, fn.Payload.
import { fn } from "@flowcatalyst/fn";
const greeting = fn.config("GREETING");const orders = fn.db("main");
fn.webhook("POST /events/order-created", onOrderCreated, { timeoutMs: 10_000, maxBodyBytes: 256 * 1024 });fn.platform("GET /orders/{id}", getOrder);fn.open("GET /healthz", health);
fn.subscribe("shop:orders:order:created", "/events/order-created", { mode: "IMMEDIATE" });fn.schedule("0 */15 * * * *", "/events/order-created", { timezone: "Africa/Johannesburg" });fn.httpAllow("api.stripe.com");fn.emits("shop:orders:order:invoiced");Endpoint options: timeoutMs, maxBodyBytes, cors. Subscription options: mode, maxRetries,
dataOnly, timeoutSeconds. Schedule options: timezone, payload.
flowcatalyst_fn::export!(|app: &mut App| { app.webhook("POST /events/order-created", on_order_created) .platform("GET /orders/{id}", get_order) .open("GET /healthz", health) .subscribe("shop:orders:order:created", "/events/order-created") .schedule("0 */15 * * * *", "/events/order-created") .config("GREETING") .secret("STRIPE_KEY") .db("main") .http_allow("api.stripe.com") .emits("shop:orders:order:invoiced");});The Rust builder declares subscriptions and schedules with the platform defaults; it has no per-subscription mode, retry or timeout options and no per-endpoint limit options.
A JVM function has no registration API. Its describe document is a file in the jar,
META-INF/flowcatalyst/function.json, plus a jvm block naming the entrypoint class:
{ "abi": 1, "jvm": { "entrypoint": "io.example.shop.OrdersFunction" }, "endpoints": [ { "method": "GET", "path": "/healthz", "auth": "none" }, { "method": "GET", "path": "/orders/{id}", "auth": "platform" }, { "method": "POST", "path": "/events/order-created", "auth": "webhook", "timeoutMs": 10000 } ], "subscriptions": [ { "eventType": "shop:orders:order:created", "path": "/events/order-created", "mode": "IMMEDIATE" } ], "schedules": [ { "cron": "0 */15 * * * *", "timezone": "Africa/Johannesburg", "path": "/events/order-created" } ], "config": ["GREETING"], "secrets": ["STRIPE_KEY"], "db": ["main"], "httpAllow": ["api.stripe.com"], "emits": ["shop:orders:order:invoiced"]}The other keys are dispatches, platformToken and traceContexts. A method-less endpoint matches
every method; list one endpoint per method otherwise. Publishing reads this entry without running
anything (at most 1 MiB, at most 50,000 jar entries, the jar itself at most 64 MiB) and refuses a jar
without it or without jvm.entrypoint.
Endpoints and how callers authenticate
Section titled “Endpoints and how callers authenticate”Every endpoint names exactly one auth mode. There is no default.
| Declared with | Describe auth |
Who calls it | What the runner checks first |
|---|---|---|---|
Webhook |
webhook |
subscriptions, schedules, dispatch jobs | the platform’s delivery signature |
Platform |
platform |
people and services holding platform tokens | a valid platform access token; your code then checks the caller’s permissions and client access |
Open |
none |
anyone | nothing: for health checks and third-party webhooks you verify yourself |
A webhook endpoint accepts POST only (the SDKs refuse anything else at registration). Paths use Go’s
routing patterns: literal segments, {name}, and a trailing {rest...}. The most specific pattern
wins; a path that matches under another method answers 405 with Allow.
A Platform endpoint authenticates the token and nothing more. Your handler decides whether the
principal may do this: HasPermission (with * segment wildcards), CanAccessClient(id),
CanAccessClientCode("acme"). Skipping that check is the common mistake: a valid token for any
principal gets through the runner.
Each endpoint can override the function’s timeout (default 30 s) and maximum request body (default 1 MiB), and declare a CORS policy (origins, methods, headers, credentials). Without a CORS declaration the runner does nothing CORS-related for the endpoint.
Which service account signs a webhook delivery
Section titled “Which service account signs a webhook delivery”A Webhook endpoint verifies the delivery signature with the signing secret of a service account.
By default that is the application’s service account (the oldest active account linked to the
application). If deliveries to your function are signed by another account, for example the one on a
connection, give the function that account:
fcdev fn deploy shop.orders . --create --service-account shop-integration # at creationfcdev fn set shop.orders --service-account shop-integration # change itfcdev fn set shop.orders --clear-service-account # back to the application'sThe value is the account’s code or id; the platform checks that it exists, is active and that you may
use it. A function that names an account uses only that account’s secret: if the account is deactivated
or deleted, every webhook delivery is refused 401 INVALID_SIGNATURE rather than quietly falling back
to the application’s account, and the platform logs function webhook secret is empty. Credentials are
cached for one minute, so a change or a rotated secret reaches runners in about that time.
A delivery that arrives before the runner has the signing secret at all (the account was only just
attached) is answered 503 WEBHOOK_SECRET_PENDING with Retry-After: 5, not 401: the platform
retries a 503 and would not retry a 401, which would lose the delivery.
Subscriptions and schedules
Section titled “Subscriptions and schedules”Subscribe(eventType, path) asks for an event type to be delivered to one of your webhook endpoints.
Schedule(cron, path) asks for a cron firing to be. In both, the path must be a literal path that
lands on a webhook endpoint.
- Cron is 6-field, seconds first:
sec min hour day-of-month month day-of-week, so0 */15 * * * *is every 15 minutes. A 5-field expression is rejected at publish. The timezone defaults to UTC. See Cron. - A subscription without a mode keeps each message group in order and moves on past a failure
(
NEXT_ON_ERROR), like every other subscription. Ask forIMMEDIATEif you do not need ordering. Because dispatch groups are per subscriber, a function’sBLOCK_ON_ERRORsubscription blocks only its own deliveries; see Ordering. - A schedule fires exactly once per tick. Concurrency is the receiver’s job: a slow function can still be running when the next tick arrives.
Subscriptions and schedules are not created when you publish. They are created, updated or removed
when you promote a version to live, to match what that version declares. Promoting an older
version back restores its wiring. See Publish, promote and use aliases.
Capabilities
Section titled “Capabilities”| Declaration | Grants |
|---|---|
Config("KEY") / Secret("KEY") |
reading that key. Values are set on the platform per function (secrets and config) |
DB("name") |
a database handle. The connection string is a platform setting; the pool belongs to the runner |
HTTPAllow("api.example.com") or *.example.com |
outbound HTTP to that host, checked on redirects too |
Emits("app:subdomain:aggregate:event") |
emitting that event type, for your own application only |
Dispatches(target, path) |
creating dispatch jobs (guide) |
UsesPlatformToken() |
a platform access token (guide) |
TraceContexts(...) |
named trace contexts (guide) |
Promotion is refused while a config key, secret or database the version declares has no value.
Limits
Section titled “Limits”| Limit | Default | Set per function |
|---|---|---|
| Memory per instance | 64 MB | yes |
| Concurrent calls | 16 | yes |
| Timeout | 30 s | yes, and per endpoint |
| Request body | 1 MiB | yes, and per endpoint |
A function past its concurrency limit answers 429; deliveries wait and try again without spending an
attempt. A function that needs more memory than it may have fails only its own call. For the database
limits (10,000 rows or 8 MiB per result, open transactions rolled back at the end of the call) and the
outbound limits (responses over 16 MiB refused), see Functions.