-
Notifications
You must be signed in to change notification settings - Fork 43
ThrottlingConfig
Thiago da Rosa de Bustamante edited this page Feb 6, 2018
·
7 revisions
Configure throttling (Rate Limits) for API requests.
The Throttling configuration object must be included in the API config and supports the following properties:
Property | Type | Description | Required |
---|---|---|---|
timeWindow | string or number | How long to keep records of requests in memory. You can inform the amount of milisencods, or use a human-interval string. Defaults to '1 minute' | false |
delayAfter | number | Max number of connections during timeWindow before starting to delay responses. | false |
delay | string or number | How long to delay the response, multiplied by (number of recent hits - delayAfter). You can inform the amount of milisencods, or use a human-interval string | false |
max | number | Max number of connections during timeWindow before sending a 429 response. Defaults to 5. | false |
message | string | Error message returned when max is exceeded. Defaults to 'Too many requests, please try again later.' | false |
statusCode | number | HTTP status code returned when max is exceeded. Defaults to 429. | false |
headers | boolean | If true, enable header to show request limit and current usage. | false |
keyGenerator | MiddlewareConfig | An installed 'throttling/keyGenerators' middleware function, called to identify the source of the request. By default user IP address (req.ip) is used as key. |
false |
skip | MiddlewareConfig | An installed 'throttling/skip' middleware function, called to verify if the throttling engine should not intercept some requests. |
false |
handler | MiddlewareConfig | An installed 'throttling/handlers' middleware function, called when the max limit is exceeded. |
false |
disableStats | boolean | If true, disable the statistical data recording for throttling events. | false |
statsConfig | StatsConfig | Configurations for the throttling stats. | false |
Example:
{
"throttling": {
"timeWindow": "one minute",
"max": 100,
"delayAfter": 90,
"delay": "1 second",
"keyGenerator": {
"name": "myThrollingKeyMiddleware"
}
}
}