◷ 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:
- Deploy a project using the Package Builder.
- Authenticate your command by getting an authentication token.
- Execute the service by creating a request object and sending it to your Service URL.
- Retrieve the response and handle the result from the command.
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 behaviors.
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:
- Authenticate your command and get an authorization token.
- Call the service endpoint with
?async=true
in the Url. - When the call is async, the server will return code 202 (Accepted), which means the task is created to process the client request.
- 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 503 (Service Unavailable) code or 500 (Internal Server Error) code.
If the result is ready, you will be able to retrieve the result.
Response Structure
Response { InvocationId (string), CorrelationId (string), errorCode (string), messageId (string), isError (bool), result: { Output (array): [{ Name (string), Value (object) }...], Notification (array), ConclusionLog(string), Elapsed (timespan), } ExtraOutput (array):[], WorkflowInstanceId (string), Exception (string), Agent (guid), }