Your first function
A function is a small piece of first-party code that the platform runs for you: an HTTP endpoint, an event subscriber or a scheduled task, without a service of your own to deploy and operate. Functions are versioned, promoted through aliases, and isolated in a sandbox (WebAssembly for Go and Rust, a JavaScript engine for TypeScript, the JVM for Java). Functions explains the model.
In this tutorial you build a hello function for the orders application, run it on your machine,
deploy it to your local fcdev, and call it.
Before you start
Section titled “Before you start”fcdevrunning (install it). It runs a function runner in-process, with a private entry on127.0.0.1:8095.- The
ordersapplication (your first event created it), because a function’s address is<application>.<name>: this one will beorders.hello. - The toolchain for your language:
Node.js with npm. The build is esbuild, installed by the project.
Go 1.24 or later (the build is GOOS=wasip1 GOARCH=wasm, built in).
Rust with the WebAssembly target: rustup target add wasm32-unknown-unknown.
JDK 25 and Maven, and a checkout of the platform repository (the function API is installed from it into your local Maven repository).
1. Scaffold
Section titled “1. Scaffold”fcdev fn init <dir> --lang go|rust|ts --app <application> writes a starter project. The directory
name is the function name (lower-case letters, digits and hyphens).
fcdev fn init hello --lang ts --app orders --sdk-path ~/src/flowcatalyst/clientscd hello && npm installfcdev fn init hello --lang go --app orderscd hellogo get github.com/flowcatalyst/flowcatalyst/clients/fn-go@v0.5.0go mod tidyThe template’s go.mod requires the SDK at a placeholder version (v0.0.0); go get pins a
real one. With --sdk-path it uses a checkout through a replace instead.
fcdev fn init hello --lang rust --app orders --sdk-path ~/src/flowcatalyst/clientsfcdev fn init does not scaffold Java. Start from the platform repository’s example
ingestor/examples/function-hello (a Maven project), and install the function API once from
the checkout: make function-api-install.
The generated function has two endpoints and reads one configuration value:
import { fn } from "@flowcatalyst/fn";
const greeting = fn.config("GREETING");
fn.open("GET /healthz", () => fn.text(200, "ok"));fn.platform("GET /hello/{name}", (req) => fn.text(200, `${greeting.get() ?? "Hello"}, ${req.params.name}`));package main
import ( "net/http"
fn "github.com/flowcatalyst/flowcatalyst/clients/fn-go")
var greeting = fn.Config("GREETING")
func init() { fn.Open("GET /healthz", func(w http.ResponseWriter, r *http.Request) { w.Write([]byte("ok")) }) fn.Platform("GET /hello/{name}", hello)}
func main() {}
func hello(w http.ResponseWriter, r *http.Request) { g, found, err := greeting.Get(r.Context()) if err != nil || !found { g = "Hello" } w.Header().Set("Content-Type", "text/plain") w.Write([]byte(g + ", " + r.PathValue("name")))}use flowcatalyst_fn::{App, Context, Error, Request, Response};
flowcatalyst_fn::export!(|app: &mut App| { app.open("GET /healthz", health) .platform("GET /hello/{name}", hello) .config("GREETING");});
fn health(_req: &Request, _ctx: &Context) -> Result<Response, Error> { Ok(Response::new(200).with_body(b"ok".to_vec()))}
fn hello(req: &Request, ctx: &Context) -> Result<Response, Error> { let greeting = ctx.config_get("GREETING").ok().flatten().unwrap_or_else(|| "Hello".into()); let name = req.path_param("name").unwrap_or("world"); Ok(Response::new(200).with_body(format!("{greeting}, {name}").into_bytes()))}// A JVM function implements io.flowcatalyst.function.Function; the routes, their auth and the// config keys are declared in src/main/resources/META-INF/flowcatalyst/function.json.public final class HelloFunction implements Function { @Override public Result handle(Request in, FunctionContext ctx) throws Exception { return switch (in.route()) { case "GET /healthz" -> Result.json(200, "{\"status\":\"ok\"}"); case "GET /hello/{name}" -> Result.json(200, Json.mapper().writeValueAsString(Map.of( "message", ctx.config().get("GREETING").orElse("Hello") + ", " + in.pathParams().getOrDefault("name", "world")))); default -> Result.fail("no handler for " + in.route()); }; }}{ "abi": 1, "jvm": { "entrypoint": "com.example.hello.HelloFunction" }, "endpoints": [ { "method": "GET", "path": "/healthz", "auth": "none" }, { "method": "GET", "path": "/hello/{name}", "auth": "platform" } ], "config": ["GREETING"]}Every endpoint names how callers authenticate, and there is no default:
| Mode | Who calls | Checked by the runner before your code runs |
|---|---|---|
open (none in a describe document) |
anyone | nothing: health checks, or third-party webhooks you verify yourself |
| platform | people and services with a platform access token | a valid token; your code then checks the caller’s permissions |
| webhook | the platform’s subscriptions and schedules (POST only) |
the delivery signature |
fcdev fn build (run in the project directory) builds with the language’s own toolchain and then
reads the function’s describe document exactly as publishing will, so what builds here publishes.
2. Run it locally
Section titled “2. Run it locally”fcdev fn dev --config GREETING=Hifcdev fn dev --config GREETING=Hifcdev fn dev --config GREETING=Hifcdev fn dev and fcdev fn run run WebAssembly and JavaScript only. A jar is tried out by
deploying it to your local fcdev (next step), where the ingestor runtime serves it.
fcdev fn dev builds the project, serves it on the real function runner at 127.0.0.1:8099 with no
platform behind it, and rebuilds and reloads on every save (a failed build keeps the last good one
serving). It prints a curl line per endpoint. The function is served at the address local.hello:
curl http://127.0.0.1:8099/fn/local.hello/healthzcurl -H "Authorization: Bearer dev" http://127.0.0.1:8099/fn/local.hello/hello/Ada# Hi, AdaLocally any bearer token is accepted on a platform endpoint. Add --send sample.json --path /x to
send a request after every reload; see develop locally with fcdev fn dev.
3. Deploy it to your local platform
Section titled “3. Deploy it to your local platform”Stop fn dev (q and Enter), then publish the function to the fcdev you are running. The fcdev fn commands use the local credential fcdev start wrote for them.
fcdev fn deploy orders.hello . --createfcdev fn deploy orders.hello . --createfcdev fn deploy orders.hello . --createmvn -q packagefcdev fn deploy orders.hello target/hello-0.1.0.jar --createThe .jar extension makes it a JVM function (served by the ingestor runtime fcdev runs on
port 8091); a function’s runtime is fixed by its first version.
deploy builds (for a directory), publishes a new version (version 1), waits until a runner
has loaded it, and promotes it to the live alias. Here it stops short of the last step: the
version declares the GREETING config key, and promotion is refused while a declared config key,
secret or database has no value. Set it and promote:
fcdev fn set orders.hello --config GREETING=Howdyfcdev fn promote orders.hello 1fcdev fn status orders.helloPublishing changes nothing that is running; promoting is the moment a version takes effect (and the moment its subscriptions and schedules are wired).
4. Call it
Section titled “4. Call it”fcdev fn invoke orders.hello hello/Ada# Howdy, Adacurl http://127.0.0.1:8095/fn/orders.hello/healthzfcdev fn invoke calls through the runner with a platform token (--anonymous sends none); it
reaches live unless you name another alias or version (orders.hello@v1). For a JVM function, pass
the ingestor’s runner: --runner http://127.0.0.1:8091.
The console’s Functions page now lists orders.hello with its version, alias and endpoints.
What next
Section titled “What next”- Make it react to events: declare a subscription (a webhook endpoint plus an event type), or a schedule, and promote again. See declare endpoints, auth, subscriptions and schedules.
- Write a function: requests, responses, events, HTTP calls, logs, and each language’s API.
- Give a function secrets and config and switch on trace logs.
- Publish, promote and use aliases across environments, with profiles.
- Decision: functions are first-party code.