ServerAPI:Execution commands

From FlexRule Wiki
Jump to: navigation, search

FlexRule Server Execution endpoint.

Url

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

Check the URL Sections for more information on different parts of the URL.

Url Sections

The then-point URL for execution is composed based on the following sections:

  • {package name}: This is the identifier of the package that is stored in 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

Arguments

Arguments can be used as part of the Url with appending ?.

?arg1=value1&arg2=value2 
  • Identifier:
    • serviceKey: Key of service to be selected for execution. The Key is unique to a service name + its version
  • Versioning
    • serviceVersion: version string of service to be selected for execution
    • useLatestVersion: ensures that the latest version of a service is selected (true/false value)
    • useEarliestVersion: Ensures that the earliest version of a service is selected (true/false value)
Bulbgraph.png You can set these parameters as part of request object

When the versioning information of a service is not set, then the service execution is based on the scheduling settings of the service.

Constraints

  • serviceKey and serviceVersion cannot be used together.
  • serviceVersion cannot be used with either useLatestVersion or useEarliestVersion

Request

When executing a service, the request should have the structure shown below:

Request {
    inputs: [
        {
            name: (string),
            value: (object)
        },
        ...
    ],
    correlation: (string),
 
    // strategy to select a service within a package
    useLatestVersion: (boolean),
    useEarliestVersion: (boolean),
    serviceKey: (string),
    serviceVersion: (string),
    enableFullLog: (boolean)
}
Info2.png Token must be acquired prior to call for execution.
  • correlation: A string that allows to correlate response to a request
  • Selecting Service with in a package
    • serviceKey: Unique key of service
    • serviceVersion: Version of service
    • useEarliestVersion: Ensures earliest version of service is chosen
    • useLatestVersion: Ensures latest version of service is chosen
  • EnableFullLog: Sends the execution log back as part of the execution response. Look for property conclusionLog in the response.


Inputs

Inputs are a set of name-value pairs. Name is the name of parameter, and Value is the value of the parameter. Inputs must be provided in a name/value format as the above Request specification noted.

Format:

 [
    { 
         name: 'parameter_name1',
         value: YOUR_PARAMETER1_VALUE // the valid value for parameter_name1
    },
    {
         name: 'parameter_name2',
         value: YOUR_PARAMETER2_VALUE // the valid value for parameter_name2
    },
    ...
 ]

Example:

 [
   {
      name: 'a1',
      value: 23
   },
   { 
      name: 'parameter2',
      value: {
          account:'test',
          id:'123'   
       }
   }
 ]

Response

The result is a Command Response Type. However, the Result is not a ResourceAddress a type from the definition shown below.

Result {
    correlationId: (string),
    outputs: [
        {
            name: (string),
            value: (object)
        },
        ...
    ],
    exception: (string),
    notification:[
        notice {
            type: (error, info, warning),
            message: (string)
        },
        ...
    ],
    conclustionLog: (string),
    agent: (string),
    elapsed: (string of TimeSpan)
}

Example

Url

http://localhost:9000/api/services/execute/car insurance/1/premium calculator

Request

{
  correlationId: 'abcd123',
  inputs: [
            {
              name: "car",
              value: {
                Airbags:3,
                ModelYear:2007,
                Made:'Hyundai',
                Model:'IX35',
                Style:'Sedan'
              }
            }
        ]
}

Response

{
   errorMessage: null,
   isError: false,
   messageId: 63,
   result: {
       correlationId: "ancd123",
       outputs: [
           {
               name: "car",
               value: {
                   Model: "IX35",
                   Price: 0,
                   BasePremium: 400,
                   AutoPremium: 1200,
                   Style: 1,
                   ModelYear: 2007,
                   HasRollBar: false,
                   Convertible: false,
                   Age: 0,
                   HasMedicalCoverage: false,
                   UninsuredMotoristCoverage: false,
                   OccupantInjuryCategory: 3,
                   TheftCategory: 1,
                   Airbags: 3,
                   Made: "Hyundai"
               }
           }
       ],
       exception: null
   }
}

Asynchronous

FlexRule Server v3 supports long running execution of task using Asynchronous method. What you need is just add async=true to the service Url and follow below steps:

  1. Get the Authorization token
  2. Call the service end point with async=true in the Url. When the call is async, server will return code 202 (Accepted) which means the task is created to process the client request.
  3. Follow the Location service provides to retrieve the result once it is ready. If the result is not yet ready, service will return 503 (Service Unavailable) code. Which means you need to try later until you can retrieve the result.

Example

Let's deploy a logic as a service and then start calling it.

In the first step, we call the service with async=true:

FRS-async-request.png

As the result, the location of where the result can be retrieved is returned. Please note the result code is also 202 rather than 200 for a normal call.

Now we can post a request to the location and retrieve the result:

FRS-async-response.png