Set Up Functions

Set Up Function Type

  1. You can set up the functions directory in your project by navigating to your project directory and executing the following command in your CLI:
copy
$
catalyst functions:setup


The procedure is the same as initializing the functions directory during the project initialization.

  1. Select the type of function you would like to develop and press Enter .
    Setup Functions Type


The five types of functions that you can develop in Catalyst are: Basic I/O, Advanced I/O, Event, Cron, and Integration functions. To learn more about the function types and their purposes, refer to the Functions help page.


Integration Functions:

The CLI initialization process is the same for all the other function types, except the Integration functions. If you select Integration from the list, you have to perform these two extra steps before moving on to the next step:

i. Select the service that you want to integrate with. You can currently only select Cliq integration.
Setup Integration Functions

ii. Select the handlers that you require. You can learn more about this from the Integration Functions help page .
Setup Integration Functions The rest of the setup process is the same for all function types. The process only varies with the function stack.


  1. Select a stack to develop the server side functions in and press Enter . The list displays all supported runtimes. You can select the latest supported version of either Java, Node.js or Python from the list.
Note: You can include Java, Node.js or Python functions in a single function directory using the catalyst functions:add command.

Set Up a Java Function of Any Type

Set up Java Function


  1. If you are setting up a Java function, enter the reference name of the Java function when prompted and press Enter . This will also be the name of the function’s folder.
    Setup Java Function

  2. Provide the main class name of the Java function and press Enter . The CLI will then download the Java SDK package and complete the functions setup process.Setup Java Function


The Java function’s folder will be created with the main .java class file, the library JAR files, catalyst-config.json , and other configuration files. These values will be updated in the catalyst.json configuration file.


Java Function Directory


You can learn about the Java function directory structure in detail from the Project Directory Structure help page .

Set Up a Node.js Function of Any Type


  1. If you are settting up a Node.js function, provide a package name for your Node function when prompted and press Enter .
    Set up Node Function

  2. Enter the name of the entry point file and press Enter .
    Set up Node Function

  3. Enter a name for the function author and press Enter .
    Set up Node Function

  4. The CLI will then prompt you to allow installation of node dependencies. Press Y to confirm the installation, and press Enter to confirm your choice. If you don’t install all the required dependencies, it could cause errors during the function’s execution.
    Set up Node Function


The CLI will then download the Node.js SDK package and complete the function setup process.

Note: Catalyst enables you to create an Advanced I/O Node.js function in the Express template, which installs the Express.js modules. However, you will not be able to create the Express template from the CLI. But you can install Express on your system independently by executing npm install express –save from a particular function's directory to use the Express modules in it. You can learn more the Express template from the Advanced I/O Function help page .

The Node function’s directory is now set up with the .js main function file, catalyst-config.json, and the necessary node modules and configuration files if you installed the dependencies. These values will be updated in the catalyst.json configuration file.
Node Function Directory


You can learn about the Node.js function directory structure in detail from the Project Directory Structure help page .

Set Up a Python Function of Any Type

  1. If you are settting up a Python function, provide a package name for your Python function when prompted and press Enter .

  2. Enter the name of the entry point file and press Enter .

Set up Python Function

On successful initialization of the Python function, the Catalyst Python SDK package will be automatically installed for your project and an entry will be made in the requirements.txt file.

The Python function’s directory is now set up with the .py main function file, catalyst-config.json, and the requirements.txt configuration file. These values will be updated in the catalyst.json configuration file.

Set up Python Function


You can learn about the Python function directory structure in detail from the Project Directory Structure help page .

Note:
  • You can add any number of sub-folders and files in a Java, Node.js or Python function’s directory. Besides the main function file, a function’s folder can contain other sub-functions. However, the configuration files and dependencies need to be in the function directory’s root.
  • You can create sub-functions for Node.js functions through the Catalyst console , or using external editors. However, Java and Python functions can be created and updated only from the CLI.
  • You can also pull an existing function directory from the console to your local system using the catalyst pull command.

You can now work on the function that you set up. You can code the function by uploading the package to the Catalyst console, and working on it using the online editor in the console or by another editor of your choice. You can also use the functions shell to test and execute the function’s code, and then deploy it to the console.