Lua Script

Executes custom Lua code during API processing.

Use the Lua Script policy to run lightweight custom Lua code that performs data manipulation, validation, or other logic at run time.

The Lua Script policy provides extension functions and preset global variables for manipulating assembly context, messages, and variables. For detailed information about available extension functions, see Lua Script extension functions.

If your Lua source code relies on or has imports to additional modules, you may add those modules to API Manager via a programming package. See Creating a Programming Package.

For more information on the policy parameter descriptions, see DataPower Nano Gateway documentation.

Example of a Lua Script policy in code view.

kind: LuaScript
apiVersion: api.ibm.com/v1
metadata:
  name: ibm_cloud_login
  version: 1
  namespace: sample
spec: 
    source: |-
      context:run_action('set-var-1') # The editor supports only Lua scripts
      context:run_action('my-invoke') # The editor supports only Lua scripts
    actions:
      set-var-1:
        $ref: sample:set_variable_1:alpha
      my-invoke:
        $ref: sample:invoke_api_1:alpha