Introduction
TheCustom Functions primitive lets you define reusable logic using XanoScript.
Each Custom Function can be inserted into any other place you’re building logic in Xano; even other Custom Functions.
Custom Functions will typically:
- Declare their name and description
- Accept inputs
- Run one or more operations in a stack
- Return a response (optional)
Anatomy
Every XanoScript Custom Function follows a predictable structure. Here’s a quick visual overview of its main building blocks — from declaration at the top to settings at the bottom.You can find more detail about each section by continuing below.
Declaration
Every Custom Function starts with a declarative header that specifies its type, name, and description.XanoScript
Section 1: Inputs
Theinput block defines the data that will be sent to the Custom Function. You can declare types, optionality, and filters:
Hover over this image to see the XanoScript version
- Declare its type (
text,email,password, etc.) - Mark it as optional (
?) - Apply filters (
filters=trim|lower)
Learn more about the available data types
Section 2: Stack
Thestack block contains the actual logic that will be executed when the Custom Function is executed.
Hover over this image to see the XanoScript version
Each block inside stack corresponds to a function available in Xano’s visual builder:
conditional— Executes different logic based on a conditionforeach— Loop through a list of itemstext.append— Append a value to a text variabletext.capitalize— Capitalize a text valuetext.split— Split a text value into an arraytext.regex_replace— Replace a text value with a regextext.to_lower— Convert a text value to lowercasetext.count— Count the number of items in an arraytext.slice— Slice an array
Review all available functions and their XanoScript in the function reference
Section 3: Response
Theresponse block defines what data your API returns:
Hover over this image to see the XanoScript version
- The
valueassignment determines the JSON returned by the Custom Function. - Variables captured in the stack (e.g.,
$camel_case_slug) can be returned here.
Settings
Custom Function primitives support several optional settings that control authentication, tagging, caching, and version history. These settings are defined at the root level of the API block, after the input, stack, and response blocks. They affect how the endpoint behaves, how it’s documented, and how responses are cached.The
cache block configures caching behavior for the API:Detailed Example
Below, you’ll see a complete example of a typical signup API endpoint.XanoScript
What’s Next
Now that you understand how to define APIs in XanoScript, here are a few great next steps:Explore the function reference
Learn about the built-in functions available in the stack to start writing more complex logic.
Try it out in VS Code
Use the XanoScript VS Code extension with Copilot to write XanoScript in your favorite IDE.
Learn about Background Tasks
Similar to APIs and Custom Functions, Tasks are easy to build logic, but they run in the background on a specific schedule.