Sign Up
Loading...

Functions

Watch the walkthrough

Custom Functions

Create reusable server-side functions and call them from workflows.

Recorded with an earlier Twidget interface. Names, control locations and available options may differ; use the linked documentation for current guidance.

Watch tutorial (3:13)

Browse all video tutorials

In Twidget, you can build custom reusable functions. These functions can be utilized across various sections including endpoints, events, and other functions. Instead of creating the same commands repeatedly, you can create a function once and reuse it wherever necessary, making your workflow more efficient and maintainable.

Constructing Functions

Functions in Twidget are structured similarly to endpoints. However, instead of using typical endpoint inputs such as query, headers, and body, functions use data type inputs.

Inputs

Functions require specific data type inputs to operate. These inputs are defined in the inputs section of the function.

Output

Each function also has an optional output. To simplify the use of functions, you can define an output schema. The output schema acts as an internal documentation detailing what the output of the function will look like. This makes it easier to understand and utilize the function correctly.

Managing Custom Functions

All custom functions you've created can be viewed in the Your Functions section of the Add Commands sidebar. This centralized view allows you to easily manage and access your reusable functions.

Using Custom Functions

When you need to use a custom function that has inputs, you will be prompted to enter the required inputs in the Commands sidebar. This ensures that the function has all the necessary data to execute correctly.

Run shared logic automatically

Use Reusable Middleware when shared logic should run before or after endpoints, functions or events, including through workspace defaults. Use an ordinary custom function when you want to choose its call explicitly inside your command list.

Save a reusable starting point

Use Workflow templates to keep a function and its supported dependencies in your workspace library. Installing a template creates independent unpublished copies that you can adapt and test before publishing.

Related Topics

Testing

To pause an isolated test and move through commands, see [Live debugging](/docs/builder/live-debugging). In Twidget, you can easily test your endpoints and functions directly within our code builder. This guide will walk you through the steps to efficiently test your functions to ensure they meet yo...

Globals & secrets

Keep shared configuration and private values in one place. Open Global at the top of an endpoint, function or event, or open the manager from Settings. The Variables and Secrets tabs belong to the selected workspace. Use ordinary variables for reusable settings such as a default page size or service...

Background jobs

Let a server function continue in the background while the original workflow returns a job ID. This is useful for work such as preparing a report or processing a batch of records. What counts as a job?. A function or endpoint is not automatically a background job. A job is created only when a workfl...

Inputs

Overview. In Twidget, inputs are essential elements that allow you to configure endpoints and functions. Events do not use inputs. Endpoint Inputs. Endpoint inputs are used to retrieve data from requests. The available types of endpoint inputs are: 1. Path: Variables that are part of the URL path. 2...

Reusable Middleware

Middleware is a reusable workflow that runs before or after an endpoint, function or event. Build it once, then apply it wherever you need the same input checks, response formatting or logging. Create middleware. Open Middleware from the sidebar and choose Create Middleware. Give it a clear name, su...