Tutorials

Custom Functions | Building Reusable Logic and Components in Xano

One of the most powerful ways to keep your Xano backend clean and maintainable is by using custom functions. Instead of rewriting the same logic over and over across multiple API endpoints or tasks, you can define it once and call it wherever you need it. Here's how to get started.

What Are Custom Functions?

Custom functions in Xano work similarly to functions or methods you'd find in traditional programming languages. They let you encapsulate a piece of logic — like string manipulation, data formatting, or a multi-step process — into a reusable component. You can then call that function from API endpoints, other custom functions, background tasks, or triggers. The result is cleaner, more organized code that's easier to debug and faster to build with.

Creating Your First Custom Function

To create a custom function, navigate to the Library tab in the left-hand menu and select Functions at the top. Click the blue Add Function button and give it a name, description, folder path, and tag for organization.

Once created, your function has the same familiar structure as an API endpoint: inputs, a function stack, and a response. For example, you might create a toUpper function that accepts a text input, applies the to_upper filter, and returns the uppercased result. You can test it directly by providing sample input and clicking Run to confirm it works as expected.

Using a Custom Function Inside an API Endpoint

Once your function is ready, you can drop it into any API endpoint's function stack. Inside your signup endpoint, for instance, you can add the toUpper function above your Add Record step, pass in the user's name as the input, and then use the function's output variable to populate the name field before saving it to the database. This ensures every new user's name is consistently uppercased without duplicating any logic.

Converting Existing Logic into a Custom Function

Sometimes you'll build logic directly inside an API endpoint and later realize it could be reused elsewhere. Xano makes this easy with the Convert to Function option in the top-right corner of your function stack. It's a good idea to clone your endpoint first to preserve the original, then convert the stack into a named custom function. You can also hold Shift to select only specific steps in a function stack and convert just those steps — giving you fine-grained control over what gets extracted.

Why This Matters for Your Backend

Custom functions help you avoid monolithic, hard-to-maintain backends. When your logic lives in one place, updates are easy — change the function once, and every place that calls it benefits automatically. Whether you're handling text formatting, complex business rules, or multi-step processes, custom functions keep your Xano projects scalable and developer-friendly.

Sign up for Xano

Join 100,000+ people already building with Xano.
Start today and scale to millions.