Layer7 API Management

 View Only

Creating conditional statements in the CA API Gateway Policy Manager 

Jun 02, 2015 09:06 AM

Background

A conditional statement allows a software engineer to specify actions in an application based on certain conditions. For example: "If a particular condition is met then do something specific." This is known as an "if-then" construct. There are many other types of conditional statements that can be constructed in contemporary programming languages. A published service policy used by the Gateway is not a programming language in and of itself and as such does not have a direct method of performing conditional statements. Alternatively, policies can be crafted to have conditional statements or other types of logical constructs to perform specific actions based on certain stimuli.

If-then Construct

An if-then construct allows a programmer to specify a particular action to execute should a particular condition be met. It makes no accommodation for how to behave if that condition is not met and is only concerned about performing an action upon meeting of a condition. This can be crafted in a published service policy using the following:

ifThen.png

In the example above, the service policy will perform a comparison operation. If that comparison passes then it will route via HTTP to a particular endpoint. If the comparison fails then the policy will continue on and will not attempt to route a request.

If-then-else Construct

An if-then-else construct allows a programmer to specify a particular action to execute should a particular condition be met. Additionally, it allows a programmer to specify what to do if the condition is not met. This can be crafted in a published service policy using the following:

ifThenElse.png

In the example above, the service policy will perform a comparison operation. If that comparison passes then it will route via HTTP to a particular endpoint. If the comparison fails then it will route the request to a second endpoint.

Else-if Construct

An else-if construct allows a programmer to specify a particular action to execute should a particular condition be met. If that condition is not met then the program will check a new condition and perform a different action. A default action can also be specified should none of the conditions be met.

ElseIf.png

Summary

The Gateway is capable of simulating the aforementioned constructs and many other styles of conditional statements by leveraging the All assertions must evaluation to true and At least one assertion must evaluate to true assertions . These assertions behave in a predictable manner and can be applied in varying quantities and in varying levels of nesting to construct the conditional statement that meets your needs. A sample service policy that shows these constructs as illustrated is attached to this article.

Statistics
0 Favorited
18 Views
1 Files
0 Shares
2 Downloads
Attachment(s)
zip file
sampleConditionals.xml.zip   1 KB   1 version
Uploaded - May 29, 2019

Tags and Keywords

Related Entries and Links

No Related Resource entered.