Functions Deep-Dive

> Learn how to publish, version, share, and import functions.

This page builds on the Functions overview. Read that first if you are new to functions in Brickr.

Function builder vs. route builder

The function builder looks almost identical to the route builder, with two key differences:

| | Route Builder | Function Builder | |---|---------------|-----------------| | Start Node | Represents an incoming HTTP request | Represents the function being called | | End Node | Returns an HTTP response | Returns output values to the caller | | Inputs | URL params, query, headers, body | Custom input pins you define | | Outputs | HTTP status, headers, body | Custom output pins you define |

Everything else -- the canvas, the node library, wiring, and the type system -- works the same way.

Start and end nodes

Function Start

The Function Start node is the entry point. Define your function's inputs here.

1. Click the Function Start node. 2. In the configuration panel, click Add Input. 3. Set a name and type for each input. 4. The inputs appear as output pins on the right side of the Start node, ready to wire into your flow.

Function End

The Function End node is where your function finishes and returns values to the caller.

1. Add a Function End node to your flow. 2. Click it and add output pins with name and type. 3. Wire the values you want to return into the End node's input pins.

A function can have multiple paths that lead to different Function End nodes, but only the first one reached will produce the return values.

Publishing and versioning

Functions use a dev/prod model with version numbers so you can test changes safely before they affect your live routes.

Dev version

When you edit a function in the builder, you are always editing the dev version. Changes are saved immediately but do not affect any published versions or routes that use the function.

Publishing

When your function is ready:

1. Click Publish in the function builder toolbar. 2. Brickr creates a new version (e.g., v1, v2, v3). 3. The published version cannot be edited. 4. Your routes automatically use the latest published version.

Testing with the dev version

While editing, you can test the dev version of your function without publishing. Routes you own will use the dev version when you run them in dev mode. Once you are happy with the changes, publish a new version.

Other users cannot use your function until you publish at least one version, even if the function is marked as public.

Sharing functions

Making a function public

1. Open the function settings. 2. Toggle Public to on. 3. Publish at least one version.

Public functions are discoverable by other Brickr users and can be imported into their workspaces.

Importing a public function

1. Navigate to Dashboard > Functions > Import. 2. Browse or search for public functions. 3. Click Import on the function you want. 4. Select the version to import.

The imported function appears in your function list and can be used in your routes like any of your own functions.

When you import a function, you import a specific version. If the author publishes a new version, you can choose to update your import or keep the version you have.

Using the Call Function node

The Call Function node is how you use a function inside a route or another function.

1. Add a Call Function node to your flow. 2. Select the function to call. 3. The node shows input pins matching the function's inputs and output pins matching its outputs. 4. Wire inputs and outputs as you would with any other node.

Execution limits

Functions share the execution time budget of the calling route. Keep this in mind when:

  • Calling functions that make external HTTP requests.
  • Nesting function calls deeply (function A calls B calls C).
  • Calling functions inside a loop.

If a function is becoming slow, try moving expensive operations like external API calls closer to the top level of your flow rather than burying them in deeply nested functions.

What's next?

| Topic | Description | |-------|-------------| | Functions overview | Basic function concepts | | Routes | Route configuration and deployment | | Visual Editor | Builder interface reference | | Nodes | Browse all available nodes |