Functions
Intro
The Functions node allows you to add and deploy your own Javascript functions
to your API.
You can write your functions in Javacsript
and It will be excuted inside an isolated async function
that supports using Dynamic variables.
How this node works
this node will run the code you write as an isolated Javascript async function
. You can use it to run custom operations or to return
something to save as the node's response so it can be accessible from any other node using the following syntax: koxy.res.{NODE_NAME}
.
Node properties
name: node names should be unique and can't be changed.
function: write your code in
Javascript
. see how to write your functions for more information.Next: the trigger that the node should call after executing the function. click on the
next input
to get a list of available triggers.
How to write your functions
To write code in the Functions node, you can use the same syntax as you would use in a regular JavaScript async function
.
You don't write the function itself.
You only write the code/content of the function.
Example 1 (Valid)
- Valid code
const data = await fetch("https://api.github.com/search/koxy.get.{searchKeyword}");
data = await data.json();
return data;
Example 2 (Invalid)
- Invalid code
async function () {
const data = await fetch("https://api.github.com/search/K_GET.{searchKeyword}");
data = await data.json();
return data;
}
The above example will save the data
as the node's response so it can be accessed as a result dynamic variable.
Please note that this is not a recommended example and if you want to fetch data you should use the HTTP Client node instead.
Do You have to return something ?
No, You don't have to return something, You can use the functions node to do any operation that our nodes are not capable of.
Adding nested functions
Technically, You can build a whole JS application in one function node
and adding nested functions is possible, but however it's not recommended for now. We recommend adding multiple functions nodes instead.
Dynamic variables support
You can use Dynamic variables in the following properties:
- function.