Contents

Popular
 Contents

Use Case

The example demonstrates the way an API response can be customized based on the client requirements. It speaks about a web service that returns address of branch as shown in JSON below.

Target Response

The requirement is to customize this 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 below. 

Expected Proxy Response

Policies used in the Use Case

  • Assign Variable Policy - to parse the response from Target Server and define variables corresponding to different parts, added in the scope TARGET_RESPONSE
  • Build Message Policy - to customize the JSON returned by the API and include part of the original request, added to the scope PROXY_RESPONSE

Policies Used

Steps to achieve the Use Case

Parse the Response from Target Service

The response received from the Target Server is parsed and various elements in the JSON are saved as context variables using the Assign Variable Policy. Source option 'PAYLOAD' is used for this purpose with JSON Path to retrieve respective elements.

Build the Proxy Response from Parsed Variables

The variables populated in the step above is 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 below.

 

Working with JSON

Icon

Since { and } are reserved in JSON, the characters < and > are used as variable prefix and variable suffix respectively.

Adaptavist ThemeBuilder EngineAtlassian Confluence