Skip to content

Headers

Each rule in flexy contains a headers block that defines matching criteria. A header is a key-value object where each key corresponds to a field name in the incoming request object and the value is a filter expression. For a rule to trigger, every key-value pair in the headers block must evaluate to true.

Value Type MongoDB Op Used Description
string $eq Exact match
number $eq Exact match
array $in Field value must be one of the elements
null - false, rule will not trigger
boolean - false, rule will not trigger
Operator Value Type Description
eq any ==
ne any !=
gt number / string >
gte number / string >=
lt number / string <
lte number / string <=
in array only Checks if field value is in the array. Non-array will cause an error
nin array only Checks if field value is not in the array. Non-array will cause an error
regex string (valid pattern) only Invalid regex or numbers will cause an error
range Array of 2 elements [lo, hi] Inclusive range on both sides. Non-arrays cause an error. Same as key: { gte: lo, lte: hi }
unknown keys any All unknown keys are ignored

{
// mid must be one of: 100, 1, 3, 99
// array is shorthand for $in
"mid": [100, 1, 3, 99],
// currency must be RUB, USD, or EUR
// both forms are equivalent
"currency": { "in": ["RUB", "USD", "EUR"] },
"currency": ["RUB", "USD", "EUR"],
// phone field must be null
"phone": { "eq": null },
// amount between 10000 and 20000 inclusive
// both forms are equivalent
"amount": { "range": [10000, 20000] },
"amount": { "gte": 10000, "lte": 20000 },
// email must match the regex pattern
"email": { "regex": "@gmail.com$" },
// email must not be in the blocklist
"email": { "nin": ["ban1@test.com", "ban2@test.com"] },
}

If filtering finds multiple matching rules, they are sorted by the following criteria, in order. Each criterion is only used to break ties left by the previous one:

  1. Priority (descending) — the explicit priority assigned to the rule.
  2. Header key count (descending) — rules whose header defines more keys are considered more specific and win.
  3. Presence of specific keys (descending) — for each key in a service-specific list, a rule that defines the key is ranked above one that does not. Keys are checked in the listed order.
  4. CreatedAt (descending) — when all of the above are equal, the most recently created rule takes precedence.

The specific keys checked in step 3, and the order in which they are checked, depend on the service:

Service Keys checked (in order)
Commission to_profile, trader_id, agent_id, amount
Guard mid, acq_alias, amount