Test a Rule Expression
Check a CEL expression — the filter that decides when a traffic policy rule fires — and see whether it would match a sample request you describe. The API validates and evaluates it with the same variables and engine the edge uses. Nothing is saved and no endpoint is involved, so any signed-in member can call it; only a suspended account is refused.
The answer is 200 whether or not the expression is valid: read valid, then matches. An expression must evaluate to a boolean and be at most 2048 bytes. An empty expression always matches (a rule without one fires on every request).
Variables
req.method, req.path, req.host, req.query, req.scheme, req.user_agent string
From the sample
request below (req.query is the raw query string).req.headers, req.query_params map<string, string>
Keys are lowercased: write
req.headers["x-api-tier"]. A key that isn't there reads ""; test presence with "x-api-tier" in req.headers.req.cookies map<string, string>
Cookie name → value, names as sent. A missing cookie reads
"".conn.client_ip string
The sample's
client_ip.conn.ja3, vars, req.bot_score, req.bot_class, req.bot_reasons, req.verified_bot —
Available to expressions, but this tester has no input for them:
conn.ja3 is "", vars (set by set-vars rules) is empty, and the bot fields read as a person's browser — req.bot_score 99, req.bot_class "browser", no req.bot_reasons, req.verified_bot false.Request body
expression string
The CEL expression, e.g.
req.method == "POST" && req.path.startsWith("/api/").request object
The sample request. Every field is optional (an omitted string is
"", an omitted map is empty): method, path, host, query, scheme, user_agent, client_ip (strings) and headers, cookies, query_params (objects of string → string).The body may be up to 64 KiB.
Response (200 OK)
valid boolean
false when the expression doesn't compile, doesn't evaluate to a boolean, or is too long. A rule with this expression would be refused with 400.matches boolean
Whether the rule would fire for the sample request. Omitted when
valid is false.error string
Why the expression is invalid (for example
invalid expression: … or expression must evaluate to a boolean, got …). Only when valid is false.note string
empty expression always matches, or evaluation error (treated as no-match at the edge): … when the expression is valid but failed on this sample — matches is then false, which is what the edge does. Omitted otherwise.Errors
400 Bad Request
The body isn't valid JSON or is over 64 KiB (
Invalid JSON).401 Unauthorized
Missing or invalid auth.
403 Forbidden
The account is suspended (
account_suspended).415 Unsupported Media Type
The request has no
Content-Type: application/json header.Request
curl -X POST "https://api.ngris.com/v1/policies/test-expression" \
-H "X-API-KEY: <your_api_key>" \
-H "Content-Type: application/json" \
-d '{
"expression": "req.method == \"POST\" && req.path.startsWith(\"/api/\") && req.headers[\"x-api-tier\"] == \"free\"",
"request": {
"method": "POST",
"path": "/api/orders",
"host": "api.example.com",
"client_ip": "203.0.113.24",
"headers": {"X-Api-Tier": "free"}
}
}'
Response — 200 OK, matches
{
"valid": true,
"matches": true
}
Response — 200 OK, empty expression
{
"valid": true,
"matches": true,
"note": "empty expression always matches"
}