I have a proxy "X",if the incoming API request has header="abc" i need to execute quota policy "Quota A" or else "Quota B" for the proxy.I cannot have multiple products .I need to do it one proxy and one product . @Anil Sagar
Solved! Go to Solution.
Here's how I would do it.
<Flow name='example flow'> <Description>demonstrate Conditional Quota</Description> <Condition>(request.verb = "POST") and (proxy.pathsuffix = "/example")</Condition> <Request> <Step> <Name>Quota-1</Name> <Condition>request.header.HEADERNAME = "abc"</Condition> </Step> <Step> <Name>Quota-2</Name> <Condition>NOT (request.header.HEADERNAME = "abc")</Condition> </Step> </Request>
....
And then of course configure your Quota policies the way you like.
Yes. You can attach one or more quota policies in an API proxy and conditionally execute them.
Here's how I would do it.
<Flow name='example flow'> <Description>demonstrate Conditional Quota</Description> <Condition>(request.verb = "POST") and (proxy.pathsuffix = "/example")</Condition> <Request> <Step> <Name>Quota-1</Name> <Condition>request.header.HEADERNAME = "abc"</Condition> </Step> <Step> <Name>Quota-2</Name> <Condition>NOT (request.header.HEADERNAME = "abc")</Condition> </Step> </Request>
....
And then of course configure your Quota policies the way you like.
Thanks @Dino that worked good.Now I have the javascript, which parses the actual response and adds quota values to the response. How can i know which Quota policy has been excecuted and which was skipped in the flow? Is there a way to do that?
Well I suppose you could cheat and chdeck request.header.HEADERNAME in the Javascript. But that means embedding that check twice - once in the Condition and once in the JS code. A better way might be to check from within JS the values for variables like
ratelimit.{policy_name}.available.count ratelimit.{policy_name}.allowed.count ratelimit.{policy_name}.used.count
...for each of {Quota-1, Quota-2} to determine which one has fired. If you see a variables for
ratelimit.Quota-1.used.count
..then you know Quota-1 has fired.
But you must already be doing this if you are embedding quota values into the response. Right?
yes ,i used a quota value to check if it null, problem was solved.
Now i want to capture response headers which have values { "count":11,"call":122}.Then an if condition to check count value and generate a custom message basing on the condition.I tried to use extract variables policy to extract headers from the response ,but i am not able to see them in the trace file.
page.value and page.app should contain header value right?
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <ExtractVariables async="false" continueOnError="false" enabled="true" name="Extract-page-headers"> <DisplayName>Extract page headers</DisplayName> <Source>response</Source> <Header name="X-Page-Usage"> <Pattern ignoreCase="false">{value}</Pattern> </Header> <Header name="X-App-Usage "> <Pattern ignoreCase="false">{app}</Pattern> </Header> <IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables> <Source clearPayload="false">response</Source> <VariablePrefix>page</VariablePrefix> </ExtractVariables>
Hi, I think this is a new question and I think you ought to use the Ask a Question button to ask a new question. We'll answer, I promise.
User | Count |
---|---|
1 | |
1 | |
1 | |
1 | |
1 |