I wonder if there is a possibility to setup quota policy for developer’s app based on my backend service response. I would like to check if my backend returned message with status 200 (ok), and only then increase call limit counter. I do not want to charge my client when my backend is shut down or returned any kind of error.
I also want to express my thankfulness for such fast and professional answers. Thanks!
Quota policy can be attached either in the request flow or response flow. Find more about flows here.
Attach quota on response flow target endpoint & execute only if response code is 200. Please check executing policies using conditional reference here. Add conditional tag using below mentioned flow variable.
Response status code is available as flow variable {response.status.code}. For more details check here.
@Abhishek Subramanya , It’s more about either executing the policy or not. Identifier is used only to uniquely identify the quota policy. Please check my answer below for more details.
@Anil Sagar I’ve added new custom quota policy. And it is called in proxy endpoint request flow. Everything works fine.
However, in my case I need something like a quota identifier increasing. I want to prevent calling my backend using quota policy, so it needs to be placed in the proxy endpoint flow. But if quota is not exceeded, request goes to backend and after response from my backend, I would like to check response code value and conditionally increase quota allow by 1.
I probably could use Reset quota policy.I figured out that I need to retrieve actual available count for policy and increment it by 1. I made such steps:
I’ve added javascript file for quota allow count retrieve:
var quotaAllowCount = context.getVariable("ratelimit.myQuotaPolicyName.available.count");
context.setVariable("newMyQuotaPolicyAllowCount", quotaAllowCount + 1)
I’ve placed it in the target endpoint response postflow with proper conditionals.
I’ve created new Reset quota policy, but I do not know how to insert new quota allow count to Allow xml element value. Code below does not compile:
However, I saw that when response from backend is 404, javascript file is not called. Whole flow from backend to client app is passed. I want to put there a condition for checking a response status code:
My plan is to put there a policy for resetting quota call rate when this condition will result in true. However, first thing after response is an error:
Received non success response code
After that, whole flow is passed. How could I put there any kind of conditions in the case of 404 response status code from my backend?
I am turning off my backend and sending next requests. I’ve figured out that in such solution I am incrementing my ratelimit.2CallPer1MinuteQuota.available.count on each backend response. So e.x. after 4th request, client has got 7 available calls, instead of 2.
It looks like resetting policy adds to available count variable, an allowed.count value. Am I right?
What I want to achieve is not really the resetting policy. It’s more about incrementing available counter by 1, but to not exceed allowed counter.