Last active
August 9, 2023 12:09
-
-
Save tomkerkhove/cb2b5f42725bbd338f56b3c5c26424f9 to your computer and use it in GitHub Desktop.
Throttling by product, but applied on operation-level
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- | |
IMPORTANT: | |
- Policy fragment are included as-is whenever they are referenced. | |
- If using variables. Ensure they are setup before use. | |
- Copy and paste your code here or simply start coding | |
--> | |
<fragment> | |
<rate-limit-by-key calls="@(int.Parse((string)context.Variables["amountOfCalls"]))" renewal-period="@(int.Parse((string)context.Variables["renewalPeriod"]))" counter-key="@(context.Subscription.Id)" remaining-calls-variable-name="remainingCallsPerSubscription" /> | |
</fragment> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<policies> | |
<inbound> | |
<base /> | |
<include-fragment fragment-id="operation-level-rate-limiting" /> | |
</inbound> | |
<backend> | |
<base /> | |
</backend> | |
<outbound> | |
<base /> | |
<set-header name="X-RateLimit-Reset" exists-action="override"> | |
<value>@(((int)context.Variables["remainingCallsPerSubscription"]).ToString())</value> | |
</set-header> | |
</outbound> | |
<on-error> | |
<base /> | |
</on-error> | |
</policies> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<policies> | |
<inbound> | |
<set-variable name="amountOfCalls" value="10" /> | |
<set-variable name="renewalPeriod" value="60" /> | |
<base /> | |
</inbound> | |
<backend> | |
<base /> | |
</backend> | |
<outbound> | |
<base /> | |
<set-header name="X-RateLimit-Renewal" exists-action="override"> | |
<value>@((string)context.Variables["renewalPeriod"])</value> | |
</set-header> | |
<set-header name="X-RateLimit-Amount" exists-action="override"> | |
<value>@((string)context.Variables["amountOfCalls"])</value> | |
</set-header> | |
</outbound> | |
<on-error> | |
<base /> | |
</on-error> | |
</policies> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<policies> | |
<inbound> | |
<base /> | |
<rate-limit-by-key calls="@(int.Parse((string)context.Variables["amountOfCalls"]))" renewal-period="@(int.Parse((string)context.Variables["renewalPeriod"]))" counter-key="@(context.Subscription.Id)" remaining-calls-variable-name="remainingCallsPerSubscription" /> | |
</inbound> | |
<backend> | |
<base /> | |
</backend> | |
<outbound> | |
<base /> | |
<set-header name="X-RateLimit-Reset" exists-action="override"> | |
<value>@(((int)context.Variables["remainingCallsPerSubscription"]).ToString())</value> | |
</set-header> | |
</outbound> | |
<on-error> | |
<base /> | |
</on-error> | |
</policies> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment