...
The assign variable policy can be used to parse the message body to make the various parts of the message available as variables which can be used further in the proxy pipeline.
The message body could be any of the following:
...
For example, a service call made to Google Location JSON service can be parsed to obtain the variables latitude and longitude of a location and can be used further in the flow to build the a request to the target server/another service call or response responsed to the client.
This policy is preferred for simple transformations on huge data when used along with the Build Message policy. For complex transformations, below policies or combination of those policies is preferredlisted below are:
...
To add a variable, perform the following actions in the Assign Variable Policy Configuration page:
Click the Add button present at the lower-right part of the page
; a.
theInfo A default variable gets added under
panelthe Variable
panel.
Click the newly added variable name to configure source information; Source drop-down appears on the right side of the Variable panel.
Note If you want to To change the default variable name, double-click on the default name to change it.
- Click the Source drop-down list to select the source from the following options that appear in the list:
- QUERY_PARAM
- FORM_PARAM
- PATH_PARAM
- HEADER
- VARIABLE
- PAYLOAD
- CONSTANT
- JAVASCRIPT
- Provide the substantiating values for the respective source, which appears as you select the source.
Click Save to complete assigning the variable.
Warning icon false title Saving variables While navigating from one variable to another, save the Save button at the bottom has to be clicked (step 5) to make sure the configuration is saved properly.
Below The figure below shows how to add variable variables (click the image for an enlarged view).
|
Figure 1: Adding variable to assign Variable policy
Source
The Source attribute helps to provide extra information which can be used by the Variable parameters that are added. Sources are of different types which may be specified as per requirement. Below The sections below explain the same.
Anchor | ||||
---|---|---|---|---|
|
Provide the parameter name in the Param Name field. The value of the query parameter is copied to the variable.
Tip |
---|
Enable Ignore Case property |
...
if the name is not to be Case Sensitive. |
Figure 2: Query Param source properties
Form Param
Provide the parameter name in the Param Name field. The value of the form parameter Form Parameter is copied to the variable. Enable
Tip |
---|
Enable Ignore Case property |
...
if the name is not to be Case Sensitive. |
Figure 3: Form Param source properties
Path Param
Provide the path pattern in the Pattern Name property value. This Path will be used by the variable parameter.
Tip |
---|
Enable Ignore |
...
Case property if the name is not to be Case Sensitive. |
Figure 4: Path Param source properties
Header
Provide the parameter name in the Param Name field. This Header parameter will be used by the variable parameter.
Enable Ignore Case property in case you do not prefer the name
Tip |
---|
Enable Ignore Case property if the name is not to be Case Sensitive. |
Figure 5: Header source properties
...
Provide parameter name in the Param Name field, and enable Ignore Case property in case you do not prefer the name .
Tip |
---|
Enable Ignore Case property if the name is not to be Case Sensitive. |
Figure 6: Variable source properties
...
Figure 9: Constant source properties
Choose the Use Variable option to provide a variable prefix and suffix in the Variable Prefix and Variable suffix Suffix fields respectively.
Figure 10: Use Variables option under Constant source properties
Info | ||
---|---|---|
| ||
The Constant source can be used to concatenate multiple context variables simply by providing value such as {variable1} constant {variable2} |
...
Provide the script in the Value editor under the Source drop-down list for the Variable parameter to use.
...
The Javascript option can be used when there is a need to perform some complex manipulation manipulations instead of simple concatenation which is performed by the constant.
To use this option, the script must contain a function which returns a string. This method must be called inside the javascript block as shown in line no. 8.
...
In the example Customizing API Response, different parts of the JSON response from the target server are extracted using this policy.
...
In the example Invoking OAuth and Caching Access Tokens, to calculate and assign the variable to determine whether the token exists in cache or not, the java script variant is used.