API Gateway 10.11 | Using API Gateway | Usage Scenarios | Request and Response Processing | How do I transform a request using Request Transformation Policy?
 
How do I transform a request using Request Transformation Policy?
 
Request Transformation Policy Properties
Use the Request Transformation policy to modify the contents of an incoming request such as headers, payload, query parameters, path parameters, HTTP method using the configurations given by the API Provider.
The request transformation workflow is as follows:
1. The API Provider configures the Request Transformation policy in the Request Processing stage of API Gateway. The API provider configures the details about when and how to transform the contents of an incoming request.
2. The client sends the request to API Gateway.
3. API Gateway applies the transformations configured by the API Provider and transforms the incoming request.
4. API Gateway sends the transformed request to the native API.
5. Native API processes the transformed request and sends the response to API Gateway.
6. API Gateway forwards the response to the client.
Consider a scenario where you have a legacy REST API (employeeApi) that does not adhere to the REST API standards. For example, it accepts functional information such as employee name through a header employeeName instead of accepting them through query or path parameters and you want to modify the API to REST standards.
*To configure request transformation policy:
1. Click APIs in the title navigation bar.
A list of available APIs appears.
2. Select a Rest API from the list of APIs and click Edit.
3. Select Policies > Request Processing > Request Transformation.
The Request Transformation details page appears.
4. In the Condition section, select OR.
The configured transformation is applied when at least one of the conditions is satisfied.
Note:
The condition can also be set to AND operator. The configured transformation is applied only when all the set conditions are satisfied.
5. Click Add Condition to configure the conditions to evaluate the contents on the request.
a. Specify the Variable. Example, Content-Type.
b. Specify the Operator to use to relate variable and the value provided. Example, Equals.
c. Specify the Value. Example, application/json.
When you select the operator - Equals, the Condition checks if the Variable: Content-Type is equal to the Value: application/json.
d. Click Add.
6. Select Transformation Configuration > Header/Query/Path transformation.
The Header/Query/Path transformation details page appears.
7. In Add/Modify section, add the variable and set its value.
Here, native API accepts employee name through header ${request.headers.employeeName} and you want the native API to accept these values through the query parameter ${request.query.name} and expose this change to the client without exposing the query parameter.
To achieve this, set the variable and the value parameters as follows:
a. Variable: ${request.headers.employeeName}
b. Value: ${request.query.name}
c. Click Add.
Note:
For details about the variables available in API Gateway, see Variables Available in API Gateway.
8. In the Remove section, add ${request.query.name} to remove the query parameter from the request so that it does not reach the native API.
9. Click Save.
This request transformation policy configuration allows the native API to accept the header values through query parameters. The native API accepts the header values through the query parameters by transforming the query parameters to header parameters and then removing the query parameter from the incoming request.