Testing your API

Run & Debug

You can test your API using Run & Debug. It's a powerful tool that can be used on your Function Stacks to verify whether or not they are working properly. It can be found on the top right-hand corner of any API, Function, Addon or Task.

Example Request

In this example API, we are using an input to ingest a number, and then in our function stack, we first set a new variable called x1 to the same value of the input. Then, in the next two steps, we are adding 1 to the previous contents of the x1 variable. So, if our input is 5, our result is 7.

Testing your API in Xano

If you are running requests that produce large amounts of data, it can cause delays during Run & Debug. It can even cause the API Test to completely stall out if the payload is very big.

When you click Run & Debug, you are presented with a panel to fill in any inputs you have established, and an option to either Run or Debug.

  1. Authentication - Select a user to authenticate with, if your endpoint requires authentication

  2. Authentication Extras - Add additional data to the generated authentication token

  3. Inputs - Populate any inputs needed to test your endpoint

  4. Reset - Resets your inputs and input schema to the default values

  5. Format - Formats the JSON added to the input panel. Good if you are pasting a payload from an external source into Xano when testing your function stack.

  6. Debug - Launch the Debugger

  7. Run - Run your function stack

Clicking RUN will run our function stack as is, which returns our expected result of 7.

  1. Input / Result - View the provided inputs and the result of your function stack execution.

  2. Result - The response of your test run and the total execution time

  3. cURL - Copy a cURL command to your clipboard for easy testing of your API outside of Xano

  4. Auth - Copy the Authentication Token used to test your API

Once your function stack finishes executing, you can reset your inputs and run it again, view the result below the input panel, or quickly generate a cURL command and copy it to your clipboard to test your API externally.

Using the Debugger

Click DEBUG from the bottom of the Run & Debug panel to open the debugger.

This will run your function stack as normal and provide a dedicated set of tools to help you understand exactly what's happening during execution.

  1. Step Over - When working with nested function stacks (custom functions or middleware), if you don't need to debug those, just step right over them and continue with the next function in your function stack Keyboard Shortcut - Arrow Up or Arrow Down

  2. Step Into / Step Out - Step into or out of a nested function (custom function or middleware) and continue the debugging experience seamlessly Keyboard Shortcut - Alt + Arrow Up or Alt + Arrow Down

  3. Continue - Continue with execution of your function stack Keyboard Shortcut - Arrow Right or Arrow Left

  4. Enable Breakpoints - Enable or disable breakpoints as a whole

  5. Step Forwards / Step Backwards - Toggle forward or reverse execution of your function stack

  6. Result - View the result of your completed execution

  7. Watches - Use custom Javscript expressions for more complex data monitoring or calculation as your function stack executes

  8. Variables - View the current contents of your variables as the function stack executes

  9. Breakpoints - View the currently established breakpoints in your function stack

Breakpoints

You can also see all of your active breakpoints listed inside of the debugger, which updates automatically as you change breakpoints in your function stack.

You can quickly enable and disable breakpoints as a whole by using the ENABLE BREAKPOINTS toggle at the top of the debugger.

Watches

Watches are Javascript-based statements that enable custom retention or manipulation of data generated as your function stack executes.

Example #1 - When working with timestamps, show a human-readable version during execution

In this example, we are running a For Each loop on some database records. For each iteration of the loop, it performs some calculation on a timestamp field, but during debugging, not having this value human readable can make understanding if everything is working as expected more difficult.

By adding the JS code below as a watcher, we can get a human readable version of the manipulated timestamps as we step through our execution.

new Date(Number(item.created_at)).toLocaleString()

Example #2 - Get a list of all values for a specific field when looping through an array of objects

In this example, we're calling an external API and looping through some products. As we step through execution, we want to see an updated list of each product that's being added to our database without having to go through whole JSON objects.

We can definitely just add a breakpoint to our conditional statement and check the value from the Variables section of the debugger, but adding some watches can make this data more easily visible.

(item.title).includes("iPhone")
item.title

By adding the two watchers listed above, we get real time monitoring of the conditional statement's expression and the product title itself, and can quickly step through each iteration of the loop to understand exactly why an item may or may not qualify.

Last updated