How to use
Rule
All the rules managed through the rule service are stored on a database with the following schema:
{
"ruleId": { "type": "string" },
"priority": { "type": "number" },
"type": { "type": "string" },
"rules": {
"type": "array",
"items": {
"type": "object",
"properties": {
"key": { "type": "string" },
"operator": { "type": "string" },
"value": { "type": "object" },
}
}
},
"response": { "type": "object" }
}
Where:
ruleIdis a unique identifier for the rule itempriorityis used to sort rulestypeis a label used to group rulesrulesis the list of conditions that have to match in order to verify the ruleresponseis the data returned when the rule is matched
Each condition have the following fields:
keyis the path to the field used to validate the condition, e.g. "/path/to/field"operatordefines which type of operation to verify; it can be one of the following values:equalsnot_equalsinnot_ingreater_thangreater_or_equal_thanless_thanless_or_equal_than
valueis the value to use to verify the condition: the value must be consistent with theoperatorused.
Manage rules
To manage your rules the following endpoints are available:
POST /ruleUsed to create a new rule. The request body is the same as the rule schema describe above.PATCH /rule/{ruleId}Used to update a rule based on theruleId. The request body contains the rule fields to update following the rule schema describe above.DELETE /rule/{ruleId}Used to delete a rule based on theruleId.
Check rule
Using the POST /check endpoint you can use the rule service to verify if your data match some of the rules defined.
When this endpoint is called, the service performs the following steps:
- load rules from the database with the same
typedefined in the request body - sort the rules by the
priorityfield in descending order - compares the payload with the rules found
- returns the data defined in the first verified rule; if no rule is verified then a 404 is returned
The expected request body has the following schema:
{
"type": { "type": "string" },
"data": { "type": "object" }
}