You are browsing documentation for an outdated version. See the latest documentation here.

Router Expressions Language Reference for Kong Gateway

With the release of version 3.0, Kong Gateway now ships with a new router. The new router can describe routes using a domain-specific language called Expressions. Expressions can describe routes or paths as combinations of logical operations called “predicates”. This document serves as a reference for all of the available operators and fields. If you want to learn how to configure routes using Expressions read How to configure routes using Expressions.

General design

Kong router Expressions are designed as combinations of simple comparisons called “predicates”. All predicates have one of the following form:

  1. field op value
  2. transformation(field) op value

Example:

  1. http.path ^= "/prefix/"
  2. lower(http.path) ^= "/prefix/"

Note: transformations only works on fields, it will not work on the value side of the predicate. This means you can not write:

  1. http.path ^= lower("/preFIX/")

Predicates can be grouped with parenthesis () or logical operators ||, &&:

Example:

  1. (http.path ^= "/prefix/" && net.port == 80) || http.method == "POST"

Types

Router expressions are strongly typed. The operators available to each field depends on the type of that field. For example, you can not perform string comparisons on a integer type field.

Available fields

FieldDescriptionType
net.protocolThe protocol used to communicate with the upstream application.String
net.portServer end port number.Int
tls.sniServer name indication.String
http.methodHTTP methods that match a route.String
http.hostLists of domains that match a route.String
http.pathNormalized request path (without query parameters).String
http.headers.headernameValue of header Header-Name. Header names are converted to lower case, and - are replaced to .String

String

OperatorMeaning
==Equals
!=Not equals
~Regex matching
^=Prefix matching
=^Suffix matching
inContains
not inDoes not contain

String transformations

TransformationMeaning
lower()turn the uppercase letters into lowercase

Integer

OperatorMeaning
==Equals
!=Not equals
>Greater than
>=Greater than or equal
<Less than
<=Less than or equal

IP

OperatorMeaning
==Equals
!=Not equals
inContains

Boolean

OperatorMeaning
&&Logical And
||Logical Or

More information