@hsuite/throttler
A powerful and flexible rate limiting library for NestJS applications, providing robust protection against abuse and ensuring optimal resource utilization.
Features
🚀 Flexible Rate Limiting: Configure custom limits and time windows per route or globally
🔄 Multiple Storage Options: Support for Redis (distributed) and in-memory storage
🛡️ IP-Based Protection: Track and limit requests based on IP addresses
⚡ High Performance: Efficient request tracking and limit enforcement
🔌 Easy Integration: Seamless integration with NestJS applications
🎯 Custom Rules: Support for dynamic rate limiting rules
📊 Response Headers: Automatic rate limit information in response headers
Installation
Peer Dependencies
@nestjs/common: ^10.4.2
@nestjs/core: ^10.4.2
Quick Start
Basic Module Setup
Using Redis Storage
Protecting Routes
Configuration Options
Module Options
enabled
boolean
Enable/disable throttling
storage
'redis' | 'memory'
Storage backend type
settings
ThrottlerSettings
Rate limiting settings
redis?
RedisOptions
Redis connection options
ThrottlerSettings
ttl
number
Time window in seconds
limit
number
Maximum requests per window
Response Headers
The module automatically sets the following response headers:
X-RateLimit-Limit
: Maximum requests allowedX-RateLimit-Remaining
: Remaining requests in current windowX-RateLimit-Reset
: Time until window reset (in seconds)Retry-After
: When rate limit is exceeded
Advanced Usage
Custom Request Handling
Service Integration
Best Practices
Storage Selection:
Use Redis storage for distributed systems
Use memory storage for single-instance applications
Rate Limit Configuration:
Set appropriate limits based on endpoint resource usage
Consider different limits for authenticated vs unauthenticated users
Error Handling:
Implement proper error handling for rate limit exceptions
Provide clear feedback to clients when limits are exceeded
Contributing
Please read our contributing guidelines before submitting pull requests.
License
This project is licensed under the terms of the license provided by HSuite.
Support
For support and questions, please refer to the HSuite documentation or contact the support team.
Built with ❤️ by the HbarSuite Team Copyright © 2024 HbarSuite. All rights reserved.
Last updated