In the near future, the DataPower Gateway V5 Compatible offering will be used very little, as the DataPower API Gateway is touted to perform 10x faster. That being said, since the DataPower API Gateway supports If logic, with the Switch policy, you’ll learn how to do both logics with the Switch policy.
Let’s add some simple logic that is actually useful while you are doing development. The scenario would be that whenever you are testing your API, you would like to have the endpoint changed based on the APIm_Debug header value. You only want to debug if you are executing your test case data. So how would you do that?
- On the API Manager, select Develop APIs and products and click on Patient API.
- Select the Gateway tab and then Policies. From the left side, drag and drop a Switch logic policy just before invoke. The drop area is a small square on the line before invoke:
Figure 6.25 – Using Switch logic in the API
3. The Properties pane will appear and you can begin providing the relevant information. Type in a description. You can use any description or use the description in Figure 6.25.
4. The $header context variable will be referenced in Case 0 to determine the value of APIm_Debug. If its value is not true, we will take a different path for our endpoint. Click on the pencil sign next to Case 0 and a new panel will display.
5. Using the dropdowns, choose $header. Then, enter the header name as APIm_Debug. Choose the equal (=) operator and then type the true value. Click Done.
You just specified that if the APIm_Debug flag is not on, process as normal. This is representing the If statement. Now, we can create the Add otherwise case, as shown here:
Figure 6.26 – Creating an If statement
6. If you scroll down, you can see the Add otherwise button. Click that button and you will see the switch logic update showing the Otherwise branch:
Figure 6.27 – Adding the Otherwise branch
It is within the Otherwise branch that you will add a new invoke policy, specifying a patient that you will be allowed to debug.
Leave a Reply