The Request Transformer policy allows to modify the request sent by a client on the fly on Express Gateway, before hitting the downstream server.
It can currently add/remove HTTP headers to the current request and add/remove properties to the request body, as long it’s JSON or URL Encoded. It will skip the body modification in case the parsing operation does not succeed, sending the request to the downstream server untouched.
policies: - request-transformer
pipelines: pipeline1: apiEndpoints: - sampleEndpoint policies: - request-transformer: - action: body: add: hello: "'world'" headers: add: r-test: "'header value'" - proxy: - action: serviceEndpoint: backend
pipelines: pipeline1: apiEndpoints: - sampleEndpoint policies: - request-transformer: - action: body: add: hello: req.consumerId headers: add: r-test: req.requestId - proxy: - action: serviceEndpoint: backend
Note: Mind the difference between an expression and a constant string value. A constant string value must be quoted, so for example
"'world'" is a constant string value. An expression doesn’t need that:
req.consumerId is an expression.
- specification for the modifications to apply to the HTTP headers.
- specification for the modifications to apply to the HTTP body.
At least one of headers and body is required.
headers and body are defined as follows:
- an object describing the name and the value of the properties to add to the headers/body collection. The value can be an expression, so you can add values at runtime
- an array of properties that should be removed from the headers/body collection