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 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...) that is stored for a package
  • {service name}: Name of the decision inside a package

Arguments

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

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

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

Constraints

  • serviceKey and serviceVersion cannot be used together.
  • serviceVersion cannot be used with neither of useLatestVersion nor useEarliestVersion

Request

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

Request {
    token: (string),
    inputs: [
        {
            name: (string),
            value: (object)
        },
        ...
    ],
    correlation: (string),
 
    // service selection information within the server
    service: (string),
    packageVersion: (string),
    packageName: (string),
 
    // strategy to select a service within a package
    useLatestVersion: (boolean),
    useEarliestVersion: (boolean),
    serviceKey: (string),
    serviceVersion: (string),
}
Info2.png Token must be acquired prior to call for execution.

Inputs

Inputs must be provided in 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. But the Result is not a ResourceAddress a type from bellow definition.

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

Example

Url

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

Request

{
  // authentication token, if authorization is disabled, can be null
  token: 'put your tocken access key here',
 
  // A correlation identifier for the request, so you know what requests was for what reason
  correlationId: 'abcd123',
 
  // values for input parameters of service
  inputs: [
            {
              name: "car",
              value: {
                Airbags:3,
                ModelYear:2007,
                Made:'Hyundai',
                Model:'IX35',
                Style:'Sedan'
              }
            }
        ],
 
  // Address of service for execution
  service: 'Premium Calculator',
  packageVersion: '1',
  packageName: 'car insurance',
 
  // strategy to select a service within a package
  useLatestVersion:true
}

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
   }
}