Question

I have an existing apigee API proxy that has a default proxy endpoint and a default target endpoint that goes to our backend server. It has a rate-limiting (quota) policy in place and throws an error to the client when it exceeds its allotted (daily) quota. Everything's great and working as intended.

Now I want to create a new proxy endpoint (or a new resource on the existing default proxy endpoint) on this same API proxy but routes to an "empty" target endpoint; I basically just want this new proxy call to return a JSON/JSONP about the caller's current quota status (basically display the values of ratelimit.{policy}.* as described here).

what would be the best way to implement this?

Was it helpful?

Solution

If you are using the UI, you may not know where the RouteRule section is. See the blue arrow below -- click on that "Default" text to see the entire proxy file.

Proxy RouteRule

You'll probably see a RouteRule section already there that includes the TargetEndpoint but no condition. I have added a RouteRule before it with a name of "NoTarget" and a Condition but no TargetEndpoint. The RouteRules are evaluated in order from top to bottom, with the first matching condition being chosen. If the condition is satisfied, that target will be used. With no TargetEndpoint, there will be no target called. If there is no condition on a RouteRule, it always matches.

So, for the example above, if the request is GET /quotastats, there will be no target called. Otherwise, it falls through to the second RouteRule, and the default target will be called.

OTHER TIPS

You can create a new resource say "checkQuotaStatus" and perform all the logic to get the quota status, may be set it in a context variable QuotaUsedCount (ratelimit.{policy_name}.used.count would give you that). Now you can raise a fault using the raisefault policy in the flow and set the response status as 200 and content to the variable value you want to respond with, in this case quotaUsedCount. Also make sure that in your flow you don not have any condition for this fault rule. That way it will execute the raise fault policy every time without hitting your target endpoint. I hope this helps.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top