Skip to main content

limit-req

This plugin uses the leaky bucket algorithm to limit the number of requests to you service.

Attributes

NameTypeRequiredDefaultValid valuesDescription
rateintegerYesrate > 0Threshold for number or requests allowed per second allowed.
burstintegerYesburst >= 0Number of additional requests allowed to be delayed per second
key_typestringNo"var"["var", "var_combination"]User-specified key type
keystringNo"remote_addr"User-specified key for the request limiting
rejected_codestringNo503[200, ..., 599]HTTP status code returned when request limit is exceeded
rejected_msgstringNoResponse body returned when request limit is exceeded
policystringNo"local"["local", "redis", "redis-cluster"]Limit used for retrieving and limiting the rate count. local value stored count values in memory on the node while setting to 'redis' stores counters in a Redis server and shares these values across nodes.
nodelaybooleanNofalseNo delays for requests withing the burst threshold if set to true
allow_degradationbooleanNofalse[true, false]When set to true, allows plugin degradation if plugin becomes temporarily unavailable, thus allowing more requests.
groupstringNoGroup to share the counter with
redis_hoststringRequired if policy is 'redis'Address of Redis server
redis_portintegerNo6379[1,...]Port of Redis server
redis_usernamestringNoUsername for Redis authentication.
redis_passwordstringNoPassword for Redis authentication
redis_sslbooleanNoSet to true, uses SSL to connect to Redis instance
redis_ssl_verifybooleanNoSet to true, verifies the validity of the SSL certificate.
redis_databaseintegerNoredis_database >= 0redis_database >= 0Selected database of the Redis server.
redis_timeoutintegerNo[1,...]Time in milliseconds for commands submitted to the Redis server.
redis_cluster_nodesarrayrequired when policy is redis-clusterAddresses of Redis cluster nodes
redis_cluster_namestringrequired when policy is redis-clusterName of Redis cluster nodes

Enable plugin

curl https://adrsearche-us-east.photoniq.macrometa.io:9080/api/stargate/v1/routes -H "X-API-KEY: $admin_key" -X PUT -d '
{
"methods": ["GET"],
"uri": "/index.html",
"plugins": {
"limit-req": {
"rate": 8,
"burst": 2,
"rejected_code": 503,
"key_type": "var",
"key": "remote_addr"
}
},
"upstream": {
"type": "roundrobin",
"nodes": {
"127.0.0.1:9001": 1
}
}
}'

You can set the key_type to var_combination

curl https://adrsearche-us-east.photoniq.macrometa.io:9080/api/stargate/v1/routes -H "X-API-KEY: $admin_key" -X PUT -d '
{
"methods": ["GET"],
"uri": "/index.html",
"plugins": {
"limit-req": {
"rate": 8,
"burst": 2,
"rejected_code": 503,
"key_type": "var_combination",
"key": "$remote_addr"
}
},
"upstream": {
"type": "roundrobin",
"nodes": {
"127.0.0.1:9001": 1
}
}
}'

Disable plugin

Toggle the Enable button to disable the plugin or delete the plugin JSON configuration from your route configuration.