FluxyAPIFluxyAPI
Functions

Functions

Learn how to create and use reusable logic snippets across your project.

Functions

Functions are one of the most powerful features in the builder. They allow you to bundle a sequence of blocks into a single, reusable unit that can be called from any endpoint in your project.

Why use Functions?

As your project grows, you might find yourself repeating the same logic in different endpoints—such as validating a user, calculating a price, or formatting a complex response.

Functions help you:

  • Reduce Duplication: Write logic once, use it everywhere.
  • Improve Maintainability: Update a function in one place to apply changes across all endpoints that use it.
  • Enhance Readability: Keep your main endpoint flows clean by moving complex sub-processes into functions.

How Functions Work

A Function consists of three main parts:

  1. Parameters: These are the "inputs" the function expects. When you call a function, you pass values into these parameters.
  2. Logic Flow: The sequence of blocks that execute when the function is called.
  3. Response: The final output returned by the function to the calling endpoint.

Scoping & Variables

Functions operate in their own scope. This means:

  • Parameters become local variables within the function flow (e.g., a parameter named user_id is accessed as {user_id}).
  • Internal Variables: Any variables created within a function stay within that function unless they are returned in the response.
  • Request Data: By default, functions do not see the original request data (headers, body, etc.) unless you enable the "Include Request Data" toggle in the function settings.

Creating a Function

To create a new function:

  1. Navigate to the Functions tab in the sidebar of the builder.
  2. Click Create Function.
  3. Define your Parameters (names and data types).
  4. Build your logic flow starting from the Function Core block.
  5. End your flow with a Return Response or Response block to send data back to the caller.

Calling a Function

Once a function is created, you can execute it using the Execute Function block in any endpoint flow.

Pro Tip

You can call functions within other functions to create even more modular and sophisticated logic chains!

On this page