By default, ratelimiter will be initialized with default options as mentioned here. However, you can override any of the options using the Config Binding. Below is an example of how to do it with the redis datasource, you can also do it with other two datasources similarly.
enabledByDefault option in Config Binding will provide a configurable mode.
When its enabled (default value is true),it will provide a way to
ratelimit all API's except a few that are disabled using a decorator.
To disable ratelimiting for all APIs except those that are enabled using the decorator,
you can set its value to false in config binding option.
The component exposes a sequence action which can be added to your server sequence class. Adding this will trigger ratelimiter middleware for all the requests passing through.
This component also exposes a method decorator for cases where you want tp specify different rate limiting options at API method level. For example, you want to keep hard rate limit for unauthorized API requests and want to keep it softer for other API requests. In this case, the global config will be overwritten by the method decoration. Refer below.
@ratelimit(false)@authenticate(STRATEGY.BEARER)@authorize(['*'])@get('/auth/me',{description:' To get the user details',security:[{[STRATEGY.BEARER]:[],},],responses:{[STATUS_CODE.OK]:{description:'User Object',content:{[CONTENT_TYPE.JSON]:AuthUser,},},...ErrorCodes,},})asyncuserDetails(@inject(RestBindings.Http.REQUEST)req:Request,):Promise<AuthUser>{returnthis.authService.getme(req.headers.authorization);}
As action based sequence will be deprecated soon, we have provided support for middleware based sequences. If you are using middleware sequence you can add ratelimit to your application by enabling ratelimit action middleware. This can be done by binding the RateLimitSecurityBindings.CONFIG in application.ts :
If you've noticed a bug or have a question or have a feature request, search the issue tracker to see if someone else in the community has already created a ticket.
If not, go ahead and make one!
All feature requests are welcome. Implementation time may vary. Feel free to contribute the same, if you can.
If you think this extension is useful, please star it. Appreciation really helps in keeping this project alive.