#1 decision-centric automation platform
Home / Business Rule / JavaScript Decision as a Service – REST API Client for HTML/JS

JavaScript Decision as a Service – REST API Client for HTML/JS


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.


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:

<!-- Load jQuery -->
<script src="jquery-2.0.2.min.js"></script>

<!-- Load FlexRule javascript client library which is part of FlexRule Workbench -->
<script src="http://localhost:9010/flexrule/client.library.js"></script>


In the button we simply are going to call a javascript function named callFlexRule.

<input type="button" value="Calculate Premium" onclick="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
            // 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');
            error: function(response) {


This sample web application and the client library that defines FlexRuleJS are available as part of FlexRule Server installer.

Read More

  1. Synchronize Decision Service
  2. .NET Decision as a Service – REST API Client for .Net
  3. SOA for Business Rules and Logic
  4. Manage Online Business Rules
  5. Decision as a Service
  6. JavaScript Decision as a Service – REST API Client for HTML/JS
Recommended Posts

Showing 6 comments

pingbacks / trackbacks

  • […] 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 […]

Leave a Comment

You must be logged in to post a comment