You can use Request Transformer | Kong Docs to accomplish this. There is an undocumented property config.replace.uri where you can set the rewrite rule.
Unfortunately it does not seem to take uri captures into account so the request-transformer plugin can only do static replacement of uris
EDIT: After further investigation this is possible. The following manifests does the trick of having multiple routes to one service with the path rewritten
Hi @thatbenguy. Unfortunately, I did not found any documentation for this at all. I had to dig into the source code of the request-transformer-plugin. The README states that the plugin accepts a config.replace.uri parameter, however that information is missing on kong hub
Then I found several examples in the plugin’s test files where the uri_captures were referenced so I decided to try and it succeeded.
If you have trouble getting it to work, please reach out and I can see if I can help you
For the moment I just added a bunch of ingress entries for each endpoint I wanted instead of using wildcards and thus requiring the uri_captures. It’s not the cleanest solution, but for now it works.
Thanks for the reply!
UPDATE: With a bit more fiddling i was able to get it working using the uri_captures as you mentioned in your posts. THANKS!
-Ben
We have a two services (say A and B) running in their own namespace in K8s cluster and they understand these end-point /v2/A and /v2/B.
But, we have a situation where we have URI as /api/v2/A and /api/v2/B and we want to slice-off /api from the URI and send request to the upstream in the format as they understand /v2/A and /v2/B.
For this, we are using Request-Transformer plugin and we enabled the plugin Cluster-wide (globally and route wise per namespace) as shown below:
When I try this:
curl -I http://KONG_PROXY_IP:PORT/api/v2/A -----> It redirects to service A and we get 200 OK
But, when I try this:
curl -I http://KONG_PROXY_IP:PORT/api/v2/B -----> It throw 404 Not Found and error log appears on service A. I double-checked that the Ingress route points to correct service.
When I try this:
curl -I http://KONG_PROXY_IP:PORT/v2/B -----> It redirects to service B and we get 200 OK (we have another Ingres rule for /v2/B)
Here plugin only works for service A and throws “404 Not Found” for serviceB end-point. Means at one time, plugin works for one service.
I am not able to understand why it is happening.
Also please educate me what is the actual meaning of uri_captures[1] here in our case?