This directory contains examples of Service Callouts (SCO), a powerful feature in Corticon.js that allows you to extend the functionality of decision services by integrating external logic or data sources. These examples demonstrate how to use SCOs to perform tasks such as accessing external APIs, manipulating data, and integrating with third-party services.
Service Callouts enable Corticon.js decision services to interact with external systems or perform custom logic that goes beyond the built-in rule modeling capabilities. SCOs are written in JavaScript and can be used to:
- Fetch data from external APIs or databases.
- Perform asynchronous operations.
- Manipulate entities and attributes within decision services.
- Extend decision services with custom logic.
- Demonstrates how to access configuration properties defined in the decision service.
- Example: Retrieve and log configuration properties, then update entity attributes with the configuration values.
- A full read/write data connector for MarkLogic, bringing an ADC-like (Advanced Data Connector) pattern from Corticon for Java to Corticon.js.
- Read: Executes dynamic, parameterized SQL queries against MarkLogic TDE views. Query definitions are stored as JSON documents in MarkLogic and resolved at runtime, with placeholder substitution from the decision service payload — no code changes needed to modify queries.
- Write: Persists Corticon working-memory entities back to MarkLogic as JSON documents, supporting full round-trip data flows within a single decision service invocation.
- Shows how to perform asynchronous operations using the
async/awaitpattern. - Example: Fetch data asynchronously and update entity attributes with the retrieved data.
- Illustrates the use of promises with
.then()for asynchronous operations. - Note: This pattern is not recommended for Corticon.js. Use the
async/awaitpattern instead.
- Contains browser-specific examples, such as storing and retrieving data from
localStorage. - Example: Save the last-used timestamp of a decision service in the browser's
localStorage.
- Demonstrates how to call functions from an external JavaScript library within a service callout.
- Shows how to create associations between entities within a decision service.
- Example: Link products to providers based on specific attributes.
- Extends the
CreateAssociationexample by performing the association creation asynchronously.
- Examples for integrating with GraphQL APIs.
- Includes CRUD operations and fetching data from GraphQL endpoints.
- A simple "Hello World" example to get started with service callouts.
- Demonstrates localization (internationalization) in dynamic forms using service callouts.
- Shows how to integrate with MarkLogic, a NoSQL database, using service callouts.
- Demonstrates the use of multiple service callouts within a single decision service.
- Shows how to generate a random string in a service callout and write it to a target string attribute chosen in the input payload.
- Examples for making REST API calls from a service callout.
- Example: Fetch data from an external REST API and update entity attributes with the response.
- Demonstrates how to update entity attributes using custom logic in a service callout.
- Example: Modify product attributes such as price, quantity, and expiration date.
- Shows how to fetch weather data for a given latitude and longitude using a REST API.
- Example: Retrieve weather information and update entities with the results.
- Demonstrates how to serialize entities into JSON format for external use.
- Navigate to the folder corresponding to the example you want to explore.
- Follow the instructions in the respective
README.txtor source files to set up and run the example. - Review the code to understand how the service callout is implemented and integrated with Corticon.js.
- Asynchronous Operations: Use the
async/awaitpattern for asynchronous operations to ensure proper execution flow within decision services. - Error Handling: Always include error handling in your service callouts to manage unexpected issues gracefully.
- Browser-Specific Features: Be cautious when using browser-specific features like
localStorage, as they may not work in non-browser environments.