Create a New Endpoint on an existing API Proxy with “No Target Endpoint”

為{幸葍}努か 提交于 2019-11-28 14:41:09

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.

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.

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.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!