Rewrite a GET request with URl rewrite and method transform

I am trying to make a GET request transform to a POST request with a URL rewrite.

GET /foo

Desired result:
POST /bar -d ‘{json stuff}’

I’ve tried a number of things with the URL rewrite in the UI, but it doesn’t seem to work. Is there a way to do this in the UI? If not, is there a way to do it with Middleware? If so, how?


Related Issue

In addition to URL rewrite you should additionally use “Method transform” plugin.

Additionally in 2.8/1.8 you can use looping like this:

Thank you Leon, that seems to work for the translating the request.

Another question: The body transform doesn’t appear to be working now. I have a template where I’m attempting to insert a path parameter, but it isn’t including the template on the request.

Response from httpbin

  "args": {},
  "data": "",
  "files": {},
  "form": {},
  "headers": {
    "Accept": "application/json",
    "Accept-Encoding": "application/json",
    "Content-Length": "0",
    "Host": "",
    "User-Agent": "curl/7.54.0",
    "X-Authentication-Token": "<removed>"
  "json": null,
  "origin": ",,",
  "url": ""

Also, “enable context variables” is set to true

More research:
It has to do with the {{._tyk_context.path_parts[0]}} variable. If I hard code that, everything works

Try using the following expression:

{{index ._tyk_context.path_parts 0}}

In general it use Go templates syntax template package - text/template - Go Packages

1 Like

Yes, that works. I thought I saw somewhere in your docs to use path_parts[0], but it must have been something else (obviously a different language).