Condition
Evaluates rules on the incoming object: sends it out of Valid when the rules are met, out of Invalid otherwise.
What it is for
Splits the graph into two branches. When the object meets the rules it goes out of Valid, otherwise out of Invalid: only one of the two outputs emits, and the blocks connected to the other are not run. It is how you do if/else, validate an input or answer differently depending on the data.
Inputs
| Port | Type | Required | Description |
|---|---|---|---|
Data (data) | object | yes | The object to check, usually the request body. |
Outputs
| Port | Type | Description |
|---|---|---|
Valid (valid) | object | The same object, when the rules are met. |
Invalid (invalid) | object | The same object, when they are not. |
Exception (exception) | object | Every block has it: if the block fails it emits the error instead of stopping the function. |
Settings
| Setting | Type | Default | Description |
|---|---|---|---|
Mode (mode) | select | all | all: every rule is needed (AND). any: one is enough (OR). |
Rules (rules) | json | [] | List of {"field", "op", "value"}. Operators: == != > >= < <= contains exists. |
Behaviour and limits
- Without rules the object is always valid.
- Only one of the two outputs emits: the blocks connected to the other are not run.
- When the Exception output is not connected, an error stops the function, unless the graph has an Exception block.
Examples
Order above a threshold
Inputs
{
"data": {
"total": 50
}
}Settings
{
"rules": [
{
"field": "total",
"op": ">",
"value": 10
}
]
}Outputs
{
"valid": {
"total": 50
}
}Required field missing
Inputs
{
"data": {
"name": "Mario"
}
}Settings
{
"rules": [
{
"field": "email",
"op": "exists"
},
{
"field": "name",
"op": "exists"
}
]
}Outputs
{
"invalid": {
"name": "Mario"
}
}One rule is enough (OR)
Inputs
{
"data": {
"role": "admin",
"owner": false
}
}Settings
{
"mode": "any",
"rules": [
{
"field": "role",
"op": "==",
"value": "admin"
},
{
"field": "owner",
"op": "==",
"value": true
}
]
}Outputs
{
"valid": {
"role": "admin",
"owner": false
}
}Tips
- A rule's value is JSON:
10is a number,"10"a text, and a text and a number are never equal. - Connect Valid and Invalid to two Response blocks to answer differently in the two cases.
Used in
- Validate a request body Coming soon
See also
- Compare Coming soon
- Response Coming soon
- Functions and LogicBlocks