I’m surely not the only one using Kong in front of a JSON API like on the homepage here: http://jsonapi.org/
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?
Hi,
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
Host: jsonapi.org
X-Gateway-Path: /api/v4/widgets
For this, you have two solutions:
- 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).
- 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: https://konghq.com/kong-enterprise-edition/
Hope that helps,