Postman is a third-party tool often used to test calling REST services. This article will give a quick demonstration of using Postman to call InRule’s “out-of-the-box” irServer Rule Execution Service using its REST endpoint, which can be installed using the InRule installer.
In this article, you will see how to add a new rule application using irAuthor, store it in irCatalog, and execute using Postman with the irServerRule Execution Service.
Installing InRule
This example will use three components, which are highlighted below:
Authoring a rule application
To author a simple rule application and store it in irCatalog:
- Launch irAuthor.
- On the Start page, click New Rule Application.
- On the Settings page, change the name of the rule application from NewRuleApplication to HelloWorld.
- In the Entities pane, right-click on Entity1, and add a new field called Field1
- Add a new rule to set the value of Field1 to Hello World1, as shown below
- From the File menu, select Save As, and save the rule application to a local irCatalog service.
- Save the rule application in irCatalog. Select File, then Save-As, and connect to your local irCatalog service.
- Click the Test button to launch irVerify and click the Apply Rules button to test out the rule. As you can see below, it runs the rule and sets Field1 to “Hello World!”
Setting the Credentials in the web.config file
Sending the Username and Password in the JSON body as part of the REST request is no longer the best practice. We recommend setting the catalog credentials in Configuration. After setting this up once, you no longer need to add the Username and Password in every REST request.
Refer to the article, How to Set Credentials for Execution Purposes in SaaS Portal, to set the credentials on the config page.
If you choose to set credentials in the JSON body (Not recommended)
Open the Rule Execution Service web.config found here on the machine:
C:\Program Files\InRule_v5.7.3\irServer\RuleEngineService\IisService\web.config
In the following section, add the credentials:
<inrule.runtime.service>
<catalog catalogServiceUri="http://localhost/InRuleCatalogService/Service.svc" userName="admin" password="password" allowPerRequestCatalogCredentials="false"/>
...
</inrule.runtime.service>
Calling irServer® Rule Execution Service from Postman
Postman can be downloaded here: https://www.getpostman.com/
To complete this solution, launch Postman, and set up these four things:
The HTTP Method:
POST
The URL:
http://localhost/InRuleRuleEngineService/HttpService.svc/ApplyRules
The Body (using JSON):
If credentials are sent in the JSON body(Not recommended)
{
"RuleApp": {
"RepositoryRuleAppRevisionSpec":{
"RuleApplicationName":"HelloWorld"
},
"UseIntegratedSecurity":"false",
"UserName":"Admin",
"Password":"password"
},
"RuleEngineServiceOptions": {
"Overrides": ""
},
"RuleEngineServiceOutputTypes": {
"ActiveNotifications": "false",
"ActiveValidations": "false",
"EntityState": "true",
"Overrides": "false",
"RuleExecutionLog": "false"
},
"EntityName": "Entity1",
"EntityState": "{}"
}
If credentials are set using Catalog credentials in Configuration
{
"RuleApp":
{
"RepositoryRuleAppRevisionSpec":
{ "RuleApplicationName":"HelloWorld" },
"UseIntegratedSecurity":"false"
},
"RuleEngineServiceOptions": { "Overrides": "" },
"RuleEngineServiceOutputTypes":
{
"ActiveNotifications": "false",
"ActiveValidations": "false",
"EntityState": "true",
"Overrides": "false",
"RuleExecutionLog": "false"
},
"EntityName": "Entity1",
"EntityState": "{}"
}
The Header:
Content-Type:application/json
Here is what Postman looks like just before clicking the Send button:
When clicking the Send button, Postman will POST the Request to the URL and get back a response. Here is what Postman looks like after clicking the Send button. It correctly runs the rule and sets Field1 to “Hello World!”
Here is the response received:
<RuleEngineHttpServiceResponse xmlns=”https://www.inrule.com/XmlSchema/Schema” xmlns:i=”http://www.w3.org/2001/XMLSchema-instance”>
<ActiveNotifications/>
<ActiveValidations/>
<EntityState>{“Field1″:”Hello World!”}</EntityState>
<HasRuntimeErrors>false</HasRuntimeErrors>
<Overrides i:nil=”true”/>
<RequestId>00000000-0000-0000-0000-000000000000</RequestId>
<RuleExecutionLog i:nil=”true”/>
<RuleSessionState i:nil=”true”/>
<SessionId>b62c49ef-d8d9-4647-920a-4d4c63e05707</SessionId>
</RuleEngineHttpServiceResponse>
Comments
0 comments
Please sign in to leave a comment.