Variables
Variables are containers that hold information. Their sole purpose is to label and store data in memory to be sent to your front-end or used in another function.
Last updated
Variables are containers that hold information. Their sole purpose is to label and store data in memory to be sent to your front-end or used in another function.
Last updated
Variables are one of the most important concepts to understand in Xano. You can think of Variables as containers that hold information. Their sole purpose is to label and store data in memory to be sent to your front-end or used in another function.
Variables can be stored as different types and are represented in orange in the function stack. Here's an example of a variable being returned from a Query all Records function:
The company variable that gets returned might look something like this:
So if you were building an app that was displaying companies from your Database and this was sufficient, you would set this variable company to be returned as the API response.
As stated in the Function Stack section, Variables are passed through each function in the function stack. So in the example below you can see variables being passed through the stack:
The above Function Stack goes through each item in the variable company using a For Each Loop and creates a new variable called individual_company to represent each company in the company variable. There is then a Conditional function that uses dot notation to access the individual name of the company (individual_company.name) and says that if the Company name = Xano then create a new variable called success_message that says "Xano is amazing!"
Text is the most common and flexible field type. You can store anything from short names, to long paragraphs of text with emojis. You can even store raw HTML.
An array is an order collection of items that can be iterated through like ["dog", "cat" , "bird", ...]
An object is a collection of properties with key: value pairs. If we take a car for example an object might look like: { "make": "honda", "model: "civic", "year": 2005, "color": "black" }
The integer field type is specifically designed to hold numbers without decimals like 1, 2, 3 or -1, 2, 3.
The decimal type is when you really want to be specific and store numbers defined by its precision. Like Pi - 3.14159265...
A boolean value is either true or false. This sets a definitive boolean value of true.
Timestamps are stored as a unix timestamp in milliseconds and we've written extensively about how to use timestamps in Xano. In the input box if you specify NOW
, it represents the time it is when this function is executed.
A NULL value is a special marker used to indicate that a data value does not exist. In other words, it is just a placeholder to denote values that are missing or that we do not know.
Any inputs created in your function stack will behave just like variables you define using the Create Variable function.
These headers are used to pass information between the front-end calling your API and your backend.
This is a special environment variable that resolves to the IP address of the individual accessing the API Endpoint.
This is a special environment variable that contains the URI that is being accessed from the API.
This is a special environment variable that contains the query string of the URI that is being accessed from the API.
This is a special environment variable that contains which data source is being used.
The name of the branch currently processing the request
Add Environment variables to your Xano Workspace to have them accessible everywhere. This is the safe way to store sensitive API keys or identifying information so you don't have to hard code it into any API endpoint that you do.
There are several filters available that can be useful when working with variables. While we have our filters documented in detail here, let's go over a few of the most popular in relation to variables.
GET - This filter is essentially a replacement for dot notation that allows you to specify a default value if the value you're storing in a variable does not exist.
For example, if I have an API response, and I want to create a new variable based on a value of that response, but sometimes that value does not exist, I would use the GET filter to provide a default or null value if that occurs.
SET - This filter is used to set a specific value inside of an object variable.
For example, if I have an object variable that looks like this:
and I wanted to add a description, I could use the SET filter to set the path of 'description' inside of 'product'. SPRINTF - This filter allows you to substitute test with your variables, similar to the replace filter, but with a little more control over enforcement of what can be used as replacement text.
We recommend reading the dedicated documentation section for more useful filters.