Use the Response Transformation policy to modify the contents of an outgoing response
such as headers, payload, query parameters, path parameters, HTTP method using the configurations
given by the API Provider.
About this task
The response transformation workflow is as follows:
- The API Provider configures the Response Transformation policy in the Response Processing stage
of webMethods API Gateway. The API provider configures the details about when and how to transform contents of
an outgoing response.
- The client sends the request to webMethods API Gateway.
- webMethods API Gateway forwards the request to native API.
- Native API processes the request and sends response to webMethods API Gateway.
- webMethods API Gateway applies the transformations configured by the API Provider and transforms the
outgoing response.
- webMethods API Gateway forwards the transformed response to the client.
Consider a scenario, where a native API URL is moved permanently or temporarily, the native API
sends a 301 or 302 status code, and also sends the new address in the location header. However, when
webMethods API Gateway comes across the 301 or 302 status code, webMethods API Gateway reads the status code and the
location header, and redirects the request to new address mentioned in the location header. API
Gateway, then sends the response from the new address to the client. This is how 3xx status code is
handled in webMethods API Gateway.
In this scenario, if you do not want webMethods API Gateway to do the redirection, instead you want the
clients to receive the 3xx status code, and then do the redirection. This can be achieved by using
the Status Transformation policy in the Response Processing stage.
To achieve this transformation:
- Change the native API to send an intermediate 2xx status code instead of 3xx status code,
for request from webMethods API Gateway.
For example, a demo service package contains a couple of REST services - source and
destination.\
The REST service source is moved to a new address and it sends a 301 status along with location
header. However, it sends 297 status code with the location header for requests from webMethods API Gateway.
The location header contains the address for destination, which is the new address of the moved
resource.
- Configure the API in webMethods API Gateway with a Request Transformation policy to send a request
header requestOrigin with the value APIGateway. To
configure the request transformation policy, perform the following steps:
- Open the menu options and select APIs.
A list of
available APIs appears.
- Select a Rest API from the list of APIs and click
Edit.
- Select . The Request Transformation details
page appears.
- 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.
- Click Add Condition to configure the conditions to evaluate the
contents on the request.
- Specify the variable. Example, Content-Type.
- Specify the operator to use to relate variable and the value provided. Example,
Equals.
- 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.
- Click Add.
- Select Transformation Configuration > Header/Query/Path
transformation. The Header/Query/Path transformation details page
appears.
- In Add/Modify section, add the variable and set its value. Set
the Variable and Value parameters as follows.
- Variable:
${request.headers.requestOrigin}
- Value: APIGateway
-
Note: For details about the variables available in
webMethods API Gateway, see
Variable Framework.
- Click Save.
This Request Transformation policy
allows the API in webMethods API Gateway to send a request header requestOrigin with the
value APIGateway. This helps the native API identify the request from API
Gateway and send the response code 297.
- Configure the API in webMethods API Gateway with the Status Transformation policy to transform the
297 status code to 301 status code. To configure the status transformation policy, perform the
following steps.
- Click APIs in the title navigation bar. A list of available
APIs appears.
- Select a Rest API from the list of APIs and click Edit.
- Select . The Response Transformation details
page appears.
- 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.
- Click Add Condition to configure the conditions to evaluate the
contents on the request.
- Specify the Variable. Example,
${response.statusCode}
.
Note: For details about the variables available in
webMethods API Gateway, see
Variable Framework .
- Specify the operator to use to relate variable and the value provided. Example,
Equals.
- Specify the value. Example, 297. When you select the operator Equals, the Condition
checks if the Variable:
${response.statusCode}
is equal to the Value:
297.
- Click Add.
- Select . The Status transformation details
page appears.
- Specify the Code and Message values that you would like in the response. Set the Code
and Message parameters as follows:
- Code: 301
- Message: Moved Permanently
- Click Save.
This transformation policy allows the clients to receive the 301 status code, and
then redirect to the new address mentioned in location header.