Creating conditional statements in the API Gateway Policy Manager
search cancel

Creating conditional statements in the API Gateway Policy Manager

book

Article ID: 42885

calendar_today

Updated On:

Products

STARTER PACK-7 CA Rapid App Security 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.

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:

<Please see attached file for image>

A service policy using a simulated if-then construct

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:

<Please see attached file for image>

A service policy using a simulated if-then-else construct

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.

<Please see attached file for image>

A service policy using a simulated else-if construct

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.

 

Environment

Release: L7SMG299000-7.1-Mobile API Gateway-HARDWARE APPLIANCE DUAL CPU
Component:

Attachments

1558722850627000042885_sktwi1f5rjvs16wmx.jpeg get_app
1558722848794000042885_sktwi1f5rjvs16wmw.jpeg get_app
1558722846678000042885_sktwi1f5rjvs16wmv.jpeg get_app
1558534540141TEC0000001245.zip get_app