In an enterprise setup, business logic (i.d. business rules, decisions, flows…) should be extracted out of applications, services and processes and be host across multiple channels by use of a Business Rule Server. This platform enables you to share business rules and decisions for execution across any type of applications and any processes as REST API service. A very common scenario is when decisions are shared across many other applications and systems. So you possible do not want to re-write but want to reuse that decision within you mobile, JavaScript or any type of web applications. Therefore after hosting the decision as a service, a REST API interface can provide you a simple interface to execute the decisions.
However, if you use the JavaScript client library, it is even much more easier!
In this post we are going to call this decision which is host as a service.
Setup
The client library, requires jQuery, so make sure you have it references, in your HTML, and let's put together a very simple html page that grabs ‘car' information such as bellow:
In the button we simply are going to call a javascript function named callFlexRule.
Client Library
When the ‘javascript decision as a service' client library is loaded, there will be an global object call FlexRuleJS which you can:
- Step 1: Configure the master server address
- Step 2: Acquire an access token
- Step 3: Execute the decision
function callFlexRule() { // step 1: Set the execution server address (Master Server) FlexRuleJS.executionClient.configuration.masterServerAddress = "http://localhost:9000"; // Loads the input data from view var inputs = getInputs(); // step 2: grab an authentication token var token = FlexRuleJS.executionClient.acquireToken({ client_id: "app1", client_secret: "123123", }); // step 3: run the decision FlexRuleJS.executionClient.run({ // authentication token, if authorization is disabled, this line can be deleted token: token, // A correlation identifier for the request, so you know what requests was for what reason // This can be deleted also, if you don't want to track requests. correlationId: 'abcd123', // values for input parameters of decision inputs: inputs, // Address of decision for execution service: 'Calculator', packageVersion: '1', packageName: 'Car Insurance', // strategy to select a service within a package useLatestVersion = true, // handlers when execution is finished success: function (response) { // retrieve the result form output parameters. // The parameter is named 'car' in this example. var car = response.getValue('car'); updateView(car); }, error: function(response) { alert(response.statusText); } } ); }
Download
This sample web application and the client library that defines FlexRuleJS are available as part of FlexRule Server installer.
Read More
- Synchronize Decision Service
- .NET Decision as a Service – REST API Client for .Net
- SOA for Business Rules and Logic
- Manage Online Business Rules
- Decision as a Service
- JavaScript Decision as a Service – REST API Client for HTML/JS
Last updated May 13th, 2020 at 08:57 am, Published May 20th, 2015 at 08:57 am
CEO and the founder of FlexRule – He is an expert in architecture, design, and implementation of operational decisions, business rules, and process automation. Created Decision-Centric Approach, a methodology that brings People, Data, Rules, and Processes together to automate operational business decisions.
This approach is recognized by Gartner as the missing link to provide business value to organizations.
[…] or application can call to these decisions using REST API interface. For example you can call them using JavaScript or really any other platforms, technologies and […]
[…] also, you pass information (in async manner) to service and return the result back. Something like this service side decision. If you have the mix of these validations in one scenario, then I would not even bothering […]
[…] example here is a sample how you can communicate with decision service for execution by passing input parameter values in […]
[…] an example you can check decision as a service sample and see how a generic javascript can communicate to a server for […]
[…] you have installed decision server it comes with two client libraries, one is for javascript clients and the other one is for .Net […]
[…] decision can be shared across all processes and applications in different technologies (i.e. JavaScript, .Net […]