CEL Content Selector

CEL Content Selector

This content allows to specify child contents depending on the status code, and fields from the request, using a CEL expression.

Learn more about CEL at cel.dev/ You can test your CEL Expression online using the CEL Playground.

The available variables are:

  • request: the incoming request data
  • status: the beheviour selected response status code

The request has the following structure:

{
    "Method":        "<GET|POST|PUT|...>",
    "URL":           "<full_url_with_query_params>",
    "Proto":       "http",
    "ProtoMajor":    "1",
    "ProtoMinor":   "1",
    "Header":      { "Foo": ["bar"], "X-Api": ["my_api_secret"]},
    "ContentLength": 1025,
    "Host":        "www.example.com",
    "RequestURI":    "",
    "TransferEncoding": ""
}

Example of a configuration checking for the value of an expression.

"content": {
  "source": "cel_content_selector",
  "config": {
    "default": {
      "source": "stats",
      "config": {}
    },
    "conditionals": [
      {
        "expr": "request.Header[?'Pass'][?0].value() == 'yes'",
        "content": {
          "source": "file",
          "config": {
            "path": "./example/data/201_created.json"
          }
        }
      }
    ]
  }
}