Scenario: In this exercise, we will see how to use flow variables.
Steps:
1. Add an instance of Spike Arrest in Preflow for incoming request.
2. Modify the code as per requirement.
Code ( 2pm means in each 30 secs, only one call will be allowed)
<!-- This policy throttles the number of requests processed by an API Proxy protecting against performance lags and downtime -->
<SpikeArrest async="true" continueOnError="true" enabled="true" xmlns="http://www.sap.com/apimgmt">
<Rate>2pm</Rate>
<UseEffectiveCount>true</UseEffectiveCount>
</SpikeArrest>
3. Add an instance of Assign Message in Preflow for Outgoing Response.
4. Modify the code as per requirement.
<!-- This policy can be used to create or modify the standard HTTP request and response messages -->
<AssignMessage async="false" continueOnError="false" enabled="true" xmlns='http://www.sap.com/apimgmt'>
<!-- Sets a new value to the existing parameter -->
<Set>
<Payload contentType="application/json" variablePrefix="@" variableSuffix="#">
{
Spike Triggered?: "@ratelimit.spikeArrest.failed#" }
</Payload>
</Set>
<IgnoreUnresolvedVariables>false</IgnoreUnresolvedVariables>
<AssignTo createNew="false" type="response">response</AssignTo>
</AssignMessage>
5. Test the API.


No comments:
Post a Comment