Create a Function

Step-by-step guide to building backend logic in Spala.

Create a Function

Functions contain your backend logic. Each function is a reusable sequence of steps that you can attach to endpoints, tasks, triggers, agents, or other functions.

Build your first function

Go to Functions

Click Functions in the left sidebar.

Add a new function

Click Create Function and give it a descriptive name, like "List Cases" or "Create Order".

Choose the right view

Start in Gherkin or Visual view to understand the function outline, then switch to Split or Code when you want more detail.

Configure each step

In Visual view, select a step and fill in its settings. Use Add Step search to find database, API, auth, control-flow, and addon steps.

Save

Press Ctrl+S (or Cmd+S) to save. Your function is now ready to attach to an endpoint, task, trigger, or agent.

The function editor showing inputs, output, and execution outline
Start from the readable outline to review inputs, output, and execution path.

The editor layout

- Gherkin — A readable behavior outline for reviewing what the function does.
- Visual — Editable step blocks and inputs.
- Split — Visual and Code together.
- Code — JavaScript for advanced editing.

Common steps to start with

| Step           | What to use it for                                  |
|---------------|-----------------------------------------------------|
| Set Variable  | Store a value: greeting = "Hello, " + input.name |
| Database Query| Read or write data: select, insert, update, delete  |
| If/Else       | Add a condition: if vars.user exists, else 404    |
| Return        | Send the response: return vars.cases               |

Good to know

A single function can be used by multiple endpoints. You can also call one function from another using a Run Function step.

Tips

- Duplicate a function — Right-click a function and choose Duplicate to create a copy you can modify.
- Name functions descriptively — Use names like "List Cases", "Create Order", "Send Welcome Email" so you can find them quickly.
- Keep functions focused — One function per action. If a function gets too long, split it into smaller functions and use Run Function to call them.
Variables & Data
/flows/variables
Set and use variables in your functions
Code View
/flows/code-view
See and edit the JavaScript version
Try & Runs
/flows/debugging
Test your functions with sample data