0

hello i am trying applying rate limiting on azure api management by json body value i have rule like that

<rate-limit-by-key calls="6" renewal-period="180" counter-key="@(context.Request.Body.As<JObject>()["phoneNumber"].ToString())" increment-condition="@(context.Response.StatusCode >= 200 && context.Response.StatusCode < 300)" />

but rate limiting not working.

ismkdc
  • 1
  • 1

2 Answers2

0

My test was succesful.

Request-Body:

{
   "phoneNumber": "+1234"
}

Policy:

    <inbound>
      <base />
      <rate-limit-by-key calls="6" renewal-period="180" counter-key="@(context.Request.Body.As<JObject>()["phoneNumber"].ToString())" increment-condition="@(context.Response.StatusCode >= 200 && context.Response.StatusCode < 300)" />
      <return-response>
        <set-status code="200" reason="OK" />
        <set-body />
      </return-response>
    </inbound>

return-response is just used for testing.

Response-Body after a few tries:

{
  "statusCode": 429,
  "message": "Rate limit is exceeded. Try again in 174 seconds."
}

How is this different from your implementation?
Do you have a different Request-Body?

Markus Meyer
  • 3,327
  • 10
  • 22
  • 35
-2

You need to put the police after base police and before other police. One police can be overwrite it or it be executing after the rate police.