August 20, 2024

How to create custom functions in Xano

Xano logo

Creating custom functions in Xano is a game-changer for anyone looking to add flexible, custom logic to their applications without diving deep into code. Whether you're a seasoned developer or a no-code enthusiast, custom functions empower you to extend the capabilities of your backend with ease. Let’s get right into it!

Step 1: Getting Started with Xano

First things first, if you haven’t already, create an account on Xano and set up your project. Navigate to your project dashboard and click on Functions in the left-hand sidebar. This is where all the magic happens.

Step 2: Creating Your First Custom Function

  1. Create a New Function:

    • Click the New Function button.
    • Give your function a descriptive name—something that clearly indicates what it does. For instance, calculateDiscount if it calculates discounts based on inputs.
  2. Define Inputs:

    • Inputs are variables that your function will take in. Click the Add Input button and specify the name and type of each parameter. For example, if you're calculating a discount, you might need inputs like originalPrice (Number) and discountPercentage (Number).

Step 3: Adding Business Logic

This is where your function starts to take shape. You can use Xano’s pre-built blocks or write custom scripts to handle the logic.

  1. Utilize Pre-built Blocks:

    • Xano provides many pre-made blocks for common operations. For example, to perform arithmetic operations, use the number blocks.
    • Drag and drop blocks to add them to your function. Connect them to define the logic sequence.
  2. Writing Custom Code:

    • For more complex logic, you can use Xano’s custom code block.
    • Click Custom Code and select your preferred language. Xano supports popular scripting languages like JavaScript.
    • Write your code directly in the editor. For our discount example:
      ```js
      let discountedPrice = originalPrice - (originalPrice * (discountPercentage / 100));
      return discountedPrice;
      ```

Step 4: Setting Up Outputs

Outputs are crucial—they tell Xano what your function returns after execution.

  1. Add an Output:
    • Click Add Output and define the output variable. For our example, you might call it discountedPrice and set its type to Number.
    • Set the output to the result of your custom logic block or the last pre-built block in your function.

Step 5: Testing Your Function

Before you integrate your function into your app, it's wise to test it within Xano.

  1. Run Tests:

    • Click the Test Function button.
    • Provide sample input values to see if your function works as expected. If calculating discounts, input an originalPrice of 100 and a discountPercentage of 10.
  2. Review Outputs:

    • The test will show the result of your function, allowing you to verify that it performs correctly. Make adjustments as needed.

Step 6: Integration

Once you’re satisfied with your custom function, you can now integrate it into your API endpoints or use it within other workflows in Xano to power your app’s backend.

Wrapping Up

And there you have it! Creating custom functions in Xano is straightforward and powerful, enabling you to add bespoke logic to your applications effortlessly. Whether you're performing calculations, formatting data, or implementing unique business rules, custom functions in Xano open up a world of possibilities. So, go ahead and start building—it’s time to bring your ideas to life!




case studies on topic
Join 20+ companies trusting Value Added tech
tripleten logosendcloud logoallen morris companyImaguru logoCore Fabrics Logowelovenocode logoLabodet LogoTetra logo
tripleten logosendcloud logoallen morris companyImaguru logoCore Fabrics Logowelovenocode logoLabodet LogoTetra logo