Hey there! Michael from Xano here with an exciting update. You can now use lambdas (small snippets of JavaScript code) in your Xano function stack to supercharge your business logic. While you can still do everything the no-code way, lambdas offer an additional avenue or path for those who know a bit of JavaScript.
Let's dive into a quick example to see how lambdas can enhance your Xano experience.
Imagine you have a list of player objects with separate fields for first name and last name. You want to create a new field called "name" that combines these two fields. Here's how you can achieve this using a lambda:
Run the Endpoint: First, run the endpoint to see the current list of player objects with separate first name and last name fields.
Open the Lambda Editor: In your function stack, click on the "Lambda" option at the bottom. This will open the JavaScript editor.
Paste the Lambda Code: Paste the following code into the editor:
return {
...response,
data: response.data.map(player => ({
...player,
name: `${player.firstName} ${player.lastName}`
}))
}
This code creates a new name field that combines the firstName and lastName for each player object.
name field added to each player object, combining the first and last name.But what if you want to capitalize the first letter of each name? No problem! With lambdas, you can leverage JavaScript libraries like Lodash to accomplish this.
Open the Lambda Editor: Open the lambda editor again.
Update the Code: Modify the previous code to use the capitalize function from Lodash:
const _ = require('lodash');
return {
...response,
data: response.data.map(player => ({
...player,
name: `${_.capitalize(player.firstName)} ${_.capitalize(player.lastName)}`
}))
}
name field will display the first and last names with the first letter capitalized.If you need a library that's not currently available in Xano, simply let us know, and we'll be happy to add it for you. We're committed to providing a flexible environment for you to enhance your Xano experience.
Lambdas aren't limited to the function stack. You can also use them with higher-order filters throughout Xano.
Apply a Filter: Let's hide the lambda function from the previous example and apply a filter to the response.
Open the Lambda Editor: In the filter menu, select the "Map" filter, which is a higher-order filter that supports lambdas.
Paste the Lambda Code: Paste the following code into the lambda editor:
const _ = require('lodash');
return {
name: `${_.capitalize(this.name.firstName)} ${_.capitalize(this.name.lastName)}`
}
This code performs the same capitalization and name combination as before, but within the context of the higher-order filter.
Lambdas in Xano open up a world of possibilities for those who have some JavaScript knowledge. You can now blend the power of code with the simplicity of Xano's no-code approach. Whether you use lambdas in your function stack or within higher-order filters, you can supercharge your business logic and create more sophisticated applications.
Of course, if you prefer to stick to the pure no-code approach, Xano still has you covered. Lambdas are an optional tool for those who want to take advantage of them.
Thanks for reading, and happy coding (or no-coding)!
Join 100,000+ people already building with Xano.
Start today and scale to millions.
Start building for free