Scenario: You want to pass the quota available count and quota used count in response
Steps:
1. Add an instance of Quota in Preflow for incoming request.
2. Modify the code as per requirement.
Code (Allow 2 calls/1 min.)
<Quota async="false" continueOnError="false" enabled="true" xmlns="http://www.sap.com/apimgmt">
<Allow count="2"/>
<Interval>1</Interval>
<Distributed>true</Distributed>
<Synchronous>true</Synchronous>
<TimeUnit>minute</TimeUnit>
</Quota>
3. Add an instance of Assign Message in preflow for outgoing response.
<!-- 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="#">
{"Quota Available": "@ratelimit.QuotaPolicy.available.count#",
"Quota Used": "@ratelimit.QuotaPolicy.used.count#"}
</Payload>
</Set>
<IgnoreUnresolvedVariables>false</IgnoreUnresolvedVariables>
<AssignTo createNew="false" type="response">response</AssignTo>
</AssignMessage>
5. Test the API.
No comments:
Post a Comment