Execute a Function
You can execute a Catalyst Basic I/O function in any one of the ways given below, based on the HTTP request you pass with the function. You can pass the parameters to the function to be executed as the argument to a function execution method. This method differs for each HTTP request type.
The <FUNCTION_INSTANCE> used in all the code sections below is the instance defined in the Function Instance page.
Execute a GET function
You can execute a function of the HTTP GET type by passing the parameters to the executeGET() method as a Hash map:
copy<FUNCTION_INSTANCE>.executeGET( Map<String, Dynamic> params, void Function(String) onSuccess, void Function(ZCatalystException) onFailed )
Parameters:
- params: The parameters to be passed to the function as a Hash map
A sample code snippet is shown below:
copyZCatalystFunction function = ZCatalystApp.getInstance().getFunctionInstance(identifier: "LocalBackUp"); //Define the function instance function.executeGET( params: { 'id': 2345642, //Pass the params to the function }, onSuccess: (APIResponse response, String output) { print('Function output: $output'); //Actions to be executed upon success }, onFailed: (ZCatalystException exception) { print('Function execution failed: $exception'); //Actions to be executed upon failure }, );
Execute a PUT function
You can execute a function of the HTTP PUT type by passing the parameters to the executePUT() method as a Hash map. You can pass the payload in the PUT request to this method as a Hash map argument as well:
copy<FUNCTION_INSTANCE>.executePUT( Map<String, Dynamic> params, Map<String, Dynamic> body, void Function(String) onSuccess, void Function(ZCatalystException) onFailed )
Parameters:
- params: The parameters to be passed to the function as a Hash map
- body: The data payload to be passed as a Hash map
A sample code snippet is shown below:
copyZCatalystFunction function = ZCatalystApp.getInstance().getFunctionInstance(identifier: 'LocalBackUp'); var body = <String, dynamic>{ "ROWID": "2823000000098012", "Category": "Important" }; //Define the function instance and pass the payload to the Hash map function.executePUT( body: body, params: { 'id': 2345642, //Pass the params to the function }, onSuccess: (APIResponse response, String output) { print('Function output: $output'); //Actions to be executed upon success }, onFailed: (ZCatalystException exception) { print('Function execution failed: $exception'); //Actions to be executed upon failure }, );
Execute a POST function
You can execute a function of the HTTP POST type by passing the parameters to the executePOST() method as a Hash map. You can pass the payload in the POST request to this method as a Hash map argument as well:
copy<FUNCTION_INSTANCE>.executePOST( Map<String, Dynamic> params, Map<String, Dynamic> body, void Function(String) onSuccess, void Function(ZCatalystException) onFailed )
Parameters:
- params: The parameters to be passed to the function as a Hash map
- body: The data payload to be passed as a Hash map
A sample code snippet is shown below:
copyZCatalystFunction function = ZCatalystApp.getInstance().getFunctionInstance(identifier: 'LocalBackUp'); var body = <String, dynamic>{ "ROWID": "2823000000098012", "Category": "Important" //Define the function instance and pass the payload to the Hash map }; function.executePOST( body: body, onSuccess: (APIResponse response, String output) { print('Function output: $output'); //Actions to be executed upon success }, onFailed: (ZCatalystException exception) { print('Function execution failed: $exception'); //Actions to be executed upon failure }, );
Last Updated 2023-09-03 01:06:41 +0530 +0530
Yes
No
Send your feedback to us