Use Case
The This example demonstrates the way an API response can be customized based on the client requirements. It speaks about The JSON below is a web service that returns address of branch as shown in JSON belowa branch office address.
Code Block |
---|
title | Target Response |
---|
language | js |
---|
|
{"id":102,"name":"Border","streetAddress":"123 MG Road","city":"Banglore","state":"KN","zipCode":"500050"} |
The requirement is to customize this the response so that it does not contain the ID, then JSON elements must be named 'BranchName' instead of name and Location as a combination of streetAddress, city and State. The expected response is as given below.
Code Block |
---|
title | Expected Proxy Response |
---|
language | js |
---|
|
{
"BranchName":"Border",
"Location":"123 MG Road,Banglore, KN"
} |
...
- Assign Variable Policy - to parse the response from the Target Server and define variables corresponding to different parts, added add in the scope TARGET_RESPONSE.
- Build Message Policy - to customize the JSON returned by the API and to include part of the original request, added add to the scope PROXY_RESPONSE.
![Policies Used Policies Used](/documentation/download/attachments/10223859/image2014-12-26%2016%3A22%3A48.png?version=2&modificationDate=1419591165000&api=v2)
Steps to achieve the Use Case
...
The variables populated in the step above is are used to build/customize the response from the proxy server. The payload is modified using the Build Message policy. The configuration looks as shown in the figure is displayed below.
![](/documentation/download/attachments/10223859/image2014-12-26%2016%3A36%3A9.png?version=2&modificationDate=1419591966000&api=v2)
Note |
---|
|
Since Since the symbols { and } are reserved in JSON, the characters < and > are used as a variable prefix and a variable suffix respectively. |