Need to strip_path but also want original uri

I’m surely not the only one using Kong in front of a JSON API like on the homepage here:

But I want to do something like router from /api/v4/widgets
to /v1.0/widgets

Therefore I have to strip_path.

But I need to provide a links property in my api response that SHOULD contain the api/v4/... url.

Any suggestions? Is that a clear example?


In this case, you need to send the ngx.var.request_uri within the upstream request somehow (e.g. within a header):

# request made by Kong
GET /v1.0/widgets HTTP/1.1
X-Gateway-Path: /api/v4/widgets 

For this, you have two solutions:

  1. Write your own custom plugin (simply grabbing that value and inserting it in a header of the upstream request. It is fairly trivial to do, if you are familiar with custom plugins (see the Plugin Development Guide).
  2. If you have an Enterprise Edition subscription, you can use the EE request transformer plugin, which lets you inject values into the upstream request via templates you can define in the plugin’s configuration. The EE edition has a free trial period:

Hope that helps,