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:
ruleId
is a unique identifier for the rule itempriority
is used to sort rulestype
is a label used to group rulesrules
is the list of conditions that have to match in order to verify the ruleresponse
is the data returned when the rule is matched
Each condition have the following fields:
key
is the path to the field used to validate the condition, e.g. "/path/to/field"operator
defines which type of operation to verify; it can be one of the following values:equals
not_equals
in
not_in
greater_than
greater_or_equal_than
less_than
less_or_equal_than
value
is the value to use to verify the condition: the value must be consistent with theoperator
used.
Manage rules
To manage your rules the following endpoints are available:
POST /rule
Used 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
type
defined in the request body - sort the rules by the
priority
field 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" }
}