A basic rate limiter implementation filter for Clyde API gateway, which allows to limit the rate consume.
Implementation is based on limiter module.
npm install clydeio-simple-rate-limiter --save
Rate limiter filter is extremely flexible and allows limit access globally or per consumer. The filter accepts the configuration properties:
-
global
: Specifies the limits to be applied globally. It must be an object with the properties:tokens
: Number of allowed accessinterval
: Interval within the previous accesses are allowed. Allowed values are:sec/second
,min/minute
,hr/hour
andday
.
-
consumers
: Specifies the global limits per consumers. For each consumer and object withtokens
andinterval
properties must be specified.
At least one property must be specified, that is, at least global
or consumers
must be set.
{
"prefilters" : [
{
"id" : "rate-limiter",
"path" : "clydeio-simple-rate-limiter",
"config" : {
"global" : {
"tokens" : 100,
"interval" : "second"
},
...
}
}
],
"provider": [
...
]
}
{
providers: [
{
"id": "idProvider",
"context": "/provider",
"target": "http://provider_server",
"prefilters" : [
{
"id" : "rate-limiter",
"path" : "clydeio-simple-rate-limiter",
"config" : {
"global" : {
"tokens" : 100,
"interval" : "second"
}
}
}
]
}
]
}
{
providers: [
{
"id": "idProvider",
"context": "/provider",
"target": "http://provider_server",
"prefilters" : [
{
"id" : "rate-limiter",
"path" : "clydeio-simple-rate-limiter",
"config" : {
"global" : {
"tokens" : 100,
"interval" : "second"
},
"consumers" : {
"userA" : {
"tokens" : 20,
"interval" : "second"
}
}
}
}
]
}
]
}
- It has no sense configure the rate limiter filter as a global or provider's postfilter.
- Limits are applied in the order: global and consumers. Be aware when chaining limits.
The MIT License (MIT)
Copyright (c) 2015 Antonio Santiago (@acanimal)
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.