Execute using REST API

Print Friendly, PDF & Email

◷ Reading Time: 3 minutes

REST API Call

In order to execute a Logic Document as a REST API call, you will need to install FlexRule Server first.

Once FlexRule Server is ready follow the following steps:

  1. Deploy a project using the Package Builder.
  2. Authenticate your command by getting an authentication token.
  3. Execute the service by creating a request object and sending it to your Service URL.
  4. Retrieve the response and handle the result from the command.

Execution can be done in either sync or async manners.

Once a package is deployed in FlexRule Server, it can be called from any application via a REST API methods (GET and POST).

Service URL

http://{your server address}/api/services/execute/{package name}/{package version}/{service name}

The URL is based on the following sections:

  • {package name}: This is the identifier of the package that is stored on the server
  • {package version}: The version string (e.g., number, string, etc.) that is stored for a package
  • {service name}: Name of the decision inside a package

For example:

http://localhost:9000/api/services/execute/agepackage/1/person growing state

Request Structure

Request {
    EnableFullLog (bool),
    CorrelationId (string), 
    Actor (string),
    
    // Input parameters of the model (or the service)
    Inputs (array):[
         {
             Name (string),
             Value (object)
         }, ...
    ],

    // Service selection strategy options
    UseEarliestVersion (bool),
    UseLatestVersion (bool),
    ServiceKey (string),
    ServiceVersion (string),

    // Workflow and long running behaviour
    Workflow: {
      WorkflowInstanceId (string),
      QueryTasks (bool),
      ResumeInfo: {
           Title (string),
           Category (string),
           Outcome (string)
       } 
}

Service

A service can have several versions with different behaviours.

You can choose which version to execute by using the following options:

  • UseEarliestVersion: Always ensures the first version of the service will be selected.
  • UseLatestVersion: Ensures the last version of the service is chosen for execution.
  • ServiceKey: When specified, the service version associated with the service’s key will be chosen for execution.
  • ServiceVersion: The specified version of the service will be chosen for execution.

Workflow

When executing a long running workflow the request object can be extended as below:

  • WorkflowInstanceId: the instance id that is associated to a workflow.
  • QueryTasks: indicates that the request is to only query a workflow based on its context or for execution.
  • ResumeInfo: contextual information about the request to be resumed.
    • Title
    • Category
    • Outcome

Asynchronous Method

FlexRule Server 3.0+ supports long-running asynchronous execution of a task. Follow the steps below:

  1. Authenticate your command and get an authorization token.
  2. Call the service endpoint with ?async=true in the Url.
  3. When the call is async, the server will return code 202 (Accepted) which means the task is created to process the client request.
  4. Follow the location service provided in order to retrieve the result once it is ready.
    If the result is not yet ready, the service will return a 503 (Service Unavailable) code.
    If the result is ready you will be able to retrieve the result.
Updated on August 9, 2019

Was this article helpful?

Related Articles