API Gateway 10.15 | Getting Started with API Gateway | Request and Response Transformation | Use case 2: Response Message Transformation
 
Use case 2: Response Message Transformation
You want to display a custom message based on the response, depending on the value of the X-Api-Provider-Secret header.
Before you begin
Ensure that you have Manage APIs or Activate/Deactivate APIs functional privilege. If you are an Administrator, you would have this privilege by default.
To transform the response message
1. Click APIs in the title navigation bar.
A list of available APIs appears.
2. Open e-commerce API. For example, you can use the sample ConsumerAPI from the Github repository.
3. Click Edit to add the Response Transformation policy to the Consumer API.
4. Select Policies > Response Processing > Response Transformation.
Response transformation condition
The Response Transformation policy properties section appears.
5. 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.
6. Click Add Condition to configure the conditions to evaluate the contents on the request.
7. Provide the following information:
a. Variable: ${request.headers.X-Api-Provider-Secret}
b. Operator: Equals
c. Value: Accepted
8. Click Add.
The condition checks the value of the X-Api-Provider-Secret header to determine the appropriate transformation. In this case, Accepted.
9. Select Transformation Configuration > Status Transformation.
Status transformation
The Status Transformation policy properties section appears.
10. Provide the following information:
a. Code: ${response.statusCode}
b. Message: Request has been processed successfully.
11. Click Save.
API Gateway checks the value of the X-Api-Provider-Secret header to determine the appropriate transformation. If the header value is Accepted, the response status message is modified to indicate that the request is processed successfully.
Next Steps
Now that you have created a e-commerce REST API and implemented the request and response transformation policies, ensure the applied policies work as expected by utilizing API testing tools. For details about how to test the API, see Testing Request and Response Transformation Policies.