Kong / kong

🦍 The Cloud-Native API Gateway and AI Gateway.
https://konghq.com/install/#kong-community
Apache License 2.0
38.78k stars 4.77k forks source link

allow templates/string injection in request transformation #1006

Closed ahmadnassri closed 3 years ago

ahmadnassri commented 8 years ago
USE CASE

when doing consumer level transformations, it can get complex real fast, e.g.

{
  "consumer_id": "consumer-id-1",
  "api_id": "api-id",
  "name": "request-transformer",
  "config": {
    "add": {
      "querystring": {
        "consumer_id": "consumer-id-1" // manually plot the consumer id into a query string
      },
      "body": {},
      "headers": {}
    }
  }
}, {
  "consumer_id": "consumer-id-2",
  "api_id": "api-id",
  "name": "request-transformer",
  "config": {
    "add": {
      "querystring": {
        "consumer_id": "consumer-id-2" // manually plot the consumer id into a query string
      },
      "body": {},
      "headers": {}
    }
  }
}

a better alternative would be:

{
  "api_id": "api-id",
  "name": "request-transformer",
  "config": {
    "add": {
      "querystring": {
        "remote_api_key: {{ CONSUMER_ID }}"
      },
      "body": {},
      "headers": {}
    }
  }
}

this can become very useful when coupled with https://github.com/Mashape/kong/issues/550

other use cases include injecting additional properties from the execution logic, e.g. cluster info, server address, ports, etc ...

jmdacruz commented 8 years ago

I can also think about more complex transformations on the request-transformer plugin, such as duplicating headers with different names, transforming values of headers into query string parameters and viceversa, etc.

JnMik commented 7 years ago

+ 1