Routes based on Query Parameters

Hi, I’m currently testing moving a complex proxy we have in Caddy to Kong API Gateway but I realized there are some limitation regarding the routing based on headers and query params. I looked everywhere for something similar but found nothing. Not even in the Enterprise plugins.

Basically I’m trying to do a routing based on a specific query param and a Header. In Caddy it looks like this:

rewrite /microservice {
r(.*)
if {query} match ?=.*treeView=false.*
if {>clientId} match CUSTOMER-.*
to microservice-b{1}
}

Which basically routes traffic going to /microservice to /microservice-b if there is a query param that matches treeView=false (regex) and if there is a header that matches CUSTOMER-abc (regex)

I’ve tried this in Kong:

routes:
...
  paths:
  - /microservice(?<capturedData>(?=treeView=false).*)
  regex_priority: 2
  strip_path: false
  plugins:
  - name: request-transformer
    config:
      http_method: null
      replace:
        uri: /microservice-b$(uri_captures['capturedData'])
    enabled: true

But I realized the regex in the paths field only apply and capture URI Paths and not parameters.
Any idea on how to achieve this?

Thanks

1 Like

Was this achieved ? I have a similar requirement


© 2019 Kong Inc.    Terms  •  Privacy  •  FAQ