Chapter 12. The REST API for Decision Server
You can communicate with the Decision Server through the REST API.
-
The base URL for sending requests is the endpoint defined earlier, for example
http://SERVER:PORT/kie-server/services/rest/server/. -
All requests require basic HTTP Authentication or token-based authentication for the role
kie-server.
Following methods support three formats of the requests: JSON, JAXB, and XSTREAM. You must provide following HTTP headers:
Accept: set toapplication/jsonorapplication/xml.When specifying more than one accepted content type in the Accept header, be sure to include the qualifiers of preference (qvalues as defined in the HTML 1.1 standard). If you do not, unexpected behavior can occur. This is an example of a well-formed header with multiple accepted content types:
Accept: application/xml; q=0.5, application/json; q=0.9
-
X-KIE-ContentTypeis required when using the XSTREAM marshaller. In such case, set the header toXSTREAM. ValuesJSONandJAXBare allowed, but not required. When you set theContent-typetoapplication/xml, theJAXBvalue is used by default. -
Content-type: set toapplication/jsonorapplication/xml. This header corresponds with the format of your payload. --data: your payload. If the payload is in a file, start the name with an ampersand@. For example:--data @commandsRequest.json
To ensure both the request and the response are in the same format, always specify both the Content-Type and Accept HTTP headers in your application’s requests. Otherwise, you can receive a marshalling-related error from the server.
The examples use the Curl utility. You can use any REST client. Curl commands use the following parameters:
-
-u: specifies username:password for the Decision Server authentication. -
-H: specifies HTTP headers. -
-X: specifies the HTTP method of the request, that is [GET], [POST], [PUT], or [DELETE].
Red Hat Decision Manager commands will work only if your Decision Server has Red Hat Decision Manager capability. The rest of the endpoints will work only if your Decision Server has Red Hat Business Automation capabilities. Check the following URI for capabilities of your Decision Server : http://SERVER:PORT/kie-server/services/rest/server.
12.1. Red Hat Decision Manager commands
- [POST] /containers/instances/CONTAINER_ID
- Request Type
-
A single
org.kie.api.command.Commandcommand or multiples commands inBatchExecutionCommandwrapper. - Response Type
-
org.kie.server.api.model.ServiceResponse<String> - Description
-
Executes the commands sent to the specified
CONTAINER_IDand returns the commands execution results. For more information, see the supported commands below.
List of supported commands:
-
AgendaGroupSetFocusCommand -
ClearActivationGroupCommand -
ClearAgendaCommand -
ClearAgendaGroupCommand -
ClearRuleFlowGroupCommand -
DeleteCommand -
InsertObjectCommand -
ModifyCommand -
GetObjectCommand -
InsertElementsCommand -
FireAllRulesCommand -
QueryCommand -
SetGlobalCommand -
GetGlobalCommand -
GetObjectsCommand -
BatchExecutionCommand -
DisposeCommand
For more information about the commands, see the org.drools.core.command.runtime package.
[POST] Drools Commands Execution
Change into a directory of your choice and create
commandsRequest.json:{ "lookup" : null, "commands" : [ { "insert" : { "object" : "testing", "disconnected" : false, "out-identifier" : null, "return-object" : true, "entry-point" : "DEFAULT" } }, { "fire-all-rules" : { } } ] }Execute the following command:
$ curl -X POST -H 'X-KIE-ContentType: JSON' -H 'Content-type: application/json' -u 'kieserver:kieserver1!' --data @commandsRequest.json http://localhost:8080/kie-server/services/rest/server/containers/instances/myContainer
The command generates a request that sends the Insert Object and Fire All Rules commands to the server.
Lookupspecifies a ksession configured in your kjar. If you use a null lookup value, the default KIE session will be used.
An example response:
{
"type" : "SUCCESS",
"msg" : "Container hello successfully called.",
"result" : "{\n \"results\" : [ ],\n \"facts\" : [ ]\n}"
}
Where did the comment section go?
Red Hat's documentation publication system recently went through an upgrade to enable speedier, more mobile-friendly content. We decided to re-evaluate our commenting platform to ensure that it meets your expectations and serves as an optimal feedback mechanism. During this redesign, we invite your input on providing feedback on Red Hat documentation via the discussion platform.