About Corticon.js integration
- Last Updated: January 8, 2025
- 5 minute read
- Corticon.js
- Documentation
- Rules deployed as serverless functions on AWS Lambda, or Microsoft Azure Functions
- Rules integrated into a cloud work flow such as AWS Step Functions or Microsoft Flow
- Rules run on your own back end as part of your Node.js platform
- Rules bundled in a mobile app created with Xamarin, React, Vue.js, or other toolkits
- Rules executed in a browser as part of a web application
After you have created and tested your rules in the Corticon.js Studio Ruletests, you are ready to package them for deployment. When you package your rules, Corticon generates a self-contained JavaScript bundle:
- Self-contained means that it has no dependencies on other Corticon components at runtime.
- JavaScript means that it will be compatible with any JavaScript platform.
- Bundle means that the complete set of rules are produced in the scope of the Ruleflow to include all its Rulesheets and enclosed Ruleflows in a single JavaScript file.
Each bundle sets the top-level Ruleflow as the entry point to your Decision Service, tailored for the selected platform, with a wrapper that you can customize, and the rules in an obfuscated JavaScript file.
How to package rules for JavaScript deployment
When you package rules for deployment, you select the target platform.
Selecting AWS Lambda, Azure Functions, or Google Cloud Functions as the target platform generates the rules and a wrapper ready for deployment as a serverless function. After the rules are deployed, you can use them on your cloud platform—for example, to expose the decision service through a REST endpoint, to respond to a database update, or to integrate into a cloud vendor workflow system such as AWS step functions.
The Node.js target can be used for running decision services in Node server and as well to run them in Mobile applications created with NativeScript and ReactNative.
Selecting Browser generates the decision service and simple example code that demonstrates how to integrate the rules into your application.
Installing the sample project
- Launch Corticon.js Studio.
- Choose Help > Samples, and then click Open.
- Click OK.
- In Corticon.js Studio, select a project, and then select
. The dialog box opens:

- Select the Ruleflow for your application.
- Choose the Target Platform:
- Enter a preferred Bundle name so that you produce your package in a distinctly named folder. Each Ruleflow selected generates a separate package.
- Enter a preferred to Directory where your package will be placed.
- Click Next. The second panel of the
dialog opens:

- Choose the top-level entities for this package. In our example, only the Cargo entity is referenced so just that entity is selected.
- Click Finish to generate the packaged JavaScript as a Decision Service plus everything you need to deploy it. The packaging process generates a single JavaScript bundle that is the entry point for the rules, which contain all the decision logic in its enclosed components for the selected Ruleflow. The generated bundle is compressed and obfuscated. It is valid, executable JavaScript, but it is not readable and cannot be edited.
How to use the JavaScript rules API
All five platform wrappers have a lot in common. Their fundamental
difference is the flow of the operations on each platform. Each of the sample.js wrappers is self-documented.
node.sample.js file: - Include the generated rule bundle:
const decisionService = require('./decisionServiceBundle'); - Get the JSON payload from your application:
const payload = readPayload(payloadFileName); - Set the configuration:
const configuration = { logLevel: 0 }; - Execute the rules on the payload:
const result = await decisionService.execute(payload, configuration);
Customizing the wrapper
The wrappers generated by Corticon.js are sample code with extensive comments. You are free to modify them to meet your needs, or use them as reference for integrating Corticon.js rules with other code.
- Get the JSON payload to be processed.
- Execute rules on the payload.
- Do something with the result JSON payload.
- Transform the payload, for example to make it suitable to pass to Corticon.
- Enrich the payload, for example with data you read from a database
- Store the result payload, saving the output of rule processing
- Process the result payload, for example passing it to REST service or another step in a workflow
Service contracts
A service contract for a decision service shows the inputs you need to pass to the decision service as part of the input payload, and the output you can expect to receive as part of the result JSON payload.