Predicates

A predicate is a condition on the incoming request. A route carries a list of them and takes the request only when every one of them accepts it: predicates are ANDed, never ORed. A route needs at least one: one saved without any is refused, since it would match nothing. To take everything, give it a path predicate with the pattern /**.

To express an OR, write two routes - or use a predicate that already accepts a list. Several patterns, hosts, methods or values inside one predicate act as OR.

In the console

Open the route in Infra > Routes, select its Predicates section, click Add and pick the predicate in the list. The list names each one in words - Path, Host, Remote addr, Time window - where these pages give its type, path, host, remote-addr, time-window. The fields that open are the predicate's arguments, the args of each reference page; the cross beside a predicate removes it.

The Predicates section of a route, holding three predicates

In a configuration file

The same predicates are written in YAML when a route travels as a file: a configuration given to an empty gateway at its first start (MEERKAT_CONFIG_FILE, see Install), or a file opened on Meerkat > Configuration (Configuration). There is no YAML box in the route editor.

routes:
  - id: orders
    name: Orders API
    enabled: true
    order: 100
    upstream: http://orders.internal:8080
    predicates:
      - type: path
        args:
          patterns:
            - /orders/**
      - type: method
        args:
          methods:
            - GET
            - POST

That route answers a GET or a POST under /orders, and nothing else.

Which route answers

Routes are tried in ascending order (ties broken by name) and the first route whose predicates all match answers. Nothing matched at all is a 404: a page naming the path for a browser, the plain text for everything else (see Routes).

A route's access rule takes part in the choice: a caller the rule turns away falls through to the next route that matches, and is refused by the first route that turned them away only if no other one answers. A rule set to deny is the exception - a closed door stays closed.

A disabled route is not loaded, so it never matches.

The catch-all

A catch-all is not a setting: it is an ordinary route whose path predicate is /**, ordered last. It catches what no other route claimed, which is how an installation answers something of its own instead of the gateway's 404 page.

Leave a gap in the order numbers - 100, 200, 300 - so a route can be inserted between two others without renumbering the table.

Trying it before shipping

The Routing test button, in the banner of Infra > Routes, composes a fictitious request (method, path, host, header, cookie, query, client address, clock, and an identity) and, after Play, shows one line per route: takes this request for the one that answers, refused by the predicate that did not match (its detail in a tooltip), matched, but its security refuses this caller, or not evaluated for a route below the one that answered whose predicates would have matched too. The clock is part of it, so a time-window can be tried on a date that has not arrived yet. Routes describes each line.

The Routing test for GET /billing/invoices: Billing takes the request, the routes whose path predicate does not match are refused by Path, and Orders API by Path and Header

The eleven predicates

Type What it matches
cookie A cookie is present, against a list of values or a regexp.
header A header is present, against a list of values or a regexp.
host The request Host, exact names or *.suffix wildcards.
method The HTTP method.
path The request path, against one or more patterns.
query A query parameter is present, against a list of values or a regexp.
remote-addr The client address, against CIDR ranges.
time-window The request was made inside a time window.
version An API version range read from a header, a query parameter or the path.
weight A share of the traffic of a group, for a canary.
x-forwarded-remote-addr The rightmost X-Forwarded-For address, against CIDR ranges.

Anything a route does to the request once it has matched is a filter.