TreeGateway / tree-gateway

This is a full featured and free API Gateway
http://treegateway.com
MIT License
189 stars 42 forks source link

Throttling per request (not per group) #163

Closed md-tfabi closed 5 years ago

md-tfabi commented 5 years ago

Does TreeGateway let us setup throttling based on requests (per user), rather than groups? So I have 3 users hitting the same endpoint, but I still want one of them to have different thresholds. The user id is in the request header. Is there a way of achieving this within TreeGateway?

thiagobustamante commented 5 years ago

Hi @md-tfabi ,

Yes, it is possible, but you need to inform your own middleware for throttling origin identification (keyGenerator):

for example:

---
name: MyThrottledAPI
version: 1.0.0
path: throttled/
proxy:
    target:
        host: http://httpbin.org
throttling:
    timeWindow: 1 minute
    max: 250 
    keyGenerator:
        name: myKeyGen

And then create the middleware myKeyGen:

"use strict";

module.exports = function (request) {
    return request.headers['user_id'];
};
md-tfabi commented 5 years ago

Hi Thiago,

This all makes sense, I already have a keyGenerator that is generating a key by the user id. The question is, that is it possible to have a different config for a different user, eg:

user 1: timeWindow: 1day, max: 100

user 2: timeWindow: 1day, max: 10000