If then Else logic policies Policy Manager Layer7 API Gateway
search cancel

If then Else logic policies Policy Manager Layer7 API Gateway

book

Article ID: 42885

calendar_today

Updated On:

Products

CA API Gateway

Issue/Introduction

 

Introduction:

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.

 

 

Environment

Release: CA API Gateway 11.x
Component:

Resolution

Instructions:

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:

In the example above, the service policy will perform a comparison operation. If that comparison succeeds, 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:

In the example above, the service policy will perform a comparison operation. If that comparison succeeds, 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.

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.