Red Hat Training
A Red Hat training course is available for Red Hat Decision Manager
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/json
orapplication/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-ContentType
is required when using the XSTREAM marshaller. In such case, set the header toXSTREAM
. ValuesJSON
andJAXB
are allowed, but not required. When you set theContent-type
toapplication/xml
, theJAXB
value is used by default. -
Content-type
: set toapplication/json
orapplication/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.Command
command or multiples commands inBatchExecutionCommand
wrapper. - Response Type
-
org.kie.server.api.model.ServiceResponse<String>
- Description
-
Executes the commands sent to the specified
CONTAINER_ID
and 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.
Lookup
specifies 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}" }