Gateway programming model and GatewayScript

The Gateway programming model and GatewayScript support the ECMAScript language specification.

The programming model implements much of the Ecma Standard for DataPower®. ECMAScript is based on original, internet technologies, including JavaScript and JScript. For example, the Gateway programming model supports ECMAScript regular expressions.

In addition to the features of ECMAScript, the Gateway programming model implements block scoping, and more security measures in its system code. Block scoping ensures that variables are not visible outside of code blocks. More provisions for security are described in a section on security in GatewayScript.

GatewayScript programs

Gateway script includes ECMAScript, CommonJS, and DataPower-specific GatewayScript APIs. Therefore, when you write programs for GatewayScript, use programming techniques that conform to the following specifications.
  • The ECMAScript language specification defines the structures and mechanisms of the programming language. GatewayScript supports many ECMAScript 2015 (ES6) features by default, including generators, promises, and template strings. For more information, see ECMAScript 2015 (ES6) in Node.js (8.9.4 LTS).
    • One important restriction on GatewayScript programs is the use of ECMAScript in strict mode. Strict mode provides a means for controlling programming behavior so that they are more secure, reliable, readable, and manageable.
    • All characters in GatewayScript files must be encoded in the UTF-8 character set.
  • CommonJS 1.0 is the CommonJS specifications define programming interfaces that address how modules are written to be interoperable among systems. You can create custom modules by following the CommonJS specifications and can access custom modules based on precedence rules for require modules.
  • GatewayScript supports DataPower-specific objects and methods and more programming structures. For example, the Document Object Model (DOM) Core node interface defines a set of objects and interfaces for accessing and manipulating document objects.
    GatewayScript provides the following DataPower-specific methods and objects.
    • The apigw module retrieves the contents of the descriptor field in the assembly function JSON object.
    • The console module supports writing log messages to system log.
    • The crypto, jose, jwk, and jwt modules support cryptographic usage.
    • The json-xml-converter module provides conversion between JSON and XML objects.
    • The header-metadata module provides methods to access the protocol headers in requests or responses.
    • The multistep module supports for the service to call a processing rule directly from GatewayScript actions.
    • The ratelimit module supports defining keys that represent rate thresholds, counters, and counters for concurrent transactions for quota enforcement.
    • The service-metadata module supports accessing service variables.
    • The session object supports a transaction flow in a GatewayScript application to access input, output, and other contexts that are visible to the service.
    • The transform module supports accessing and manipulating the data in an XML document.
    • The urlopen module supports establishing a non-streaming connection with target servers by HTTP, HTTPS, or IBM® MQ protocol and open files in the DataPower file system.
  • The API gateway supports a different context object, which is specific to API management.
    The GatewayScript APIs for API management can access and manipulate the variables in the API context during execution of the API assembly rule. The GatewayScript APIs are used by the assembly GatewayScript action of the API gateway. The assembly GatewayScript action can use all objects and modules that the GatewayScript action supports, except the following modules.
    • fs module
    • mgmt module
    • policy-utility module