Execute the Function

A function can be executed by calling the execute() method in which the configuration (of type JSON) is passed as a parameter. The function object used in the code snippet is the function object.

Create a Function Configuration

Before executing a function, it is mandatory to set the configuration required for it. Here, the configuration specifies, the function arguments(as args) if any.

//Create the config object used to execute the function. //The args is an JSONObject to pass values to the function as parameters. var config = { "args": {"name": "xxx"}, "method":"GET" };

The supported HTTP methods are: GET, PUT, POST, PATCH, and DELETE.

The GET method is the default. If you use GET in your code, the function arguments are passed as query strings. If you use any of the other HTTP methods, the function arguments are passed in the request body.

Execute Function

The function can be executed by passing the configuration object as an argument to the execute() method.

The promise returned here will be resolved to an object in which the content key contains the output of the executed function.
//Execute the function by passing the config object var functions = catalyst.function; var functionObject = functions.functionId(FUNCTION_NAME); //can pass Function Id or Function Name as argument var functionPromise = functionObject.execute(config); functionPromise .then((response) => { response.json().then(responseBody => { console.log(responseBody); }); }) .catch((err) => { console.log(err); });

Last Updated 2023-11-14 13:20:49 +0530 +0530