Service Router

Service Router #

INFINI Gateway judges the flow direction based on routers. A typical example of router configuration is as follows:

  - name: my_router
    default_flow: default_flow
    tracing_flow: request_logging
      - method:
          - PUT
          - POST
          - "/_bulk"
          - "/{index_name}/_bulk"
          - bulk_process_flow

Router involves several important terms:

  • Flow: Handling flow of a request. Flows can be defined in three places in a router.
  • default_flow: Default handling flow, which is the main flow of service handling. Request forwarding, filtering, and caching are performed in this flow.
  • tracing_flow: Flow used to track the request status. It is independent of the default_flow. This flow is used to log requests and collect statistics.
  • rules: Requests are distributed to specific handling flows according to matching rules. Regular expressions can be used to match the methods and paths of requests.

Parameter Description #

namestringRoute name
default_flowstringName of the default request handling flow
tracing_flowstringName of the flow used to trace a request
rulesarrayList of routing rules to be applied in the array sequence
rules.methodstringMethod type of a request. The GET, HEAD, POST, PUT, PATCH, DELETE, CONNECT, OPTIONS, and TRACE types are supported and * indicates any type.
rules.patternstringURL path matching rule of a request. Patterns are supported and overlapping matches are not allowed.
rules.flowstringFlow to be executed after rule matching. Multiple flows can be combined and they are executed sequentially.

Pattern Syntax #

{Variable name}Variable with a name/{name}
{Variable name:regexp}Restricts the matching rule of the variable by using a regular expression./{name:[a-zA-Z]}
{Variable name:*}Any path after matching. It can be applied only to the end of a pattern./{any:*}


Pattern: /user/{user}

 /user/gordon                     match
 /user/you                        match
 /user/gordon/profile             no match
 /user/                           no match

Pattern with suffix: /user/{user}_admin

 /user/gordon_admin               match
 /user/you_admin                  match
 /user/you                        no match
 /user/gordon/profile             no match
 /user/gordon_admin/profile       no match
 /user/                           no match
Pattern: /src/{filepath:*}

 /src/                     match
 /src/somefile.go          match
 /src/subdir/somefile.go   match


  • A pattern must begin with /.
  • Any match is only used as the last rule.