The E-Commerce API includes built-in rate limiting to protect against abuse and ensure fair usage. This guide explains how rate limiting works and how to configure it.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/memoowi/e-comm-api-demo-2/llms.txt
Use this file to discover all available pages before exploring further.
Overview
Rate limiting is implemented using theexpress-rate-limit package and is automatically applied to all incoming requests through the logging middleware.
Default configuration
The API uses the following default rate limit settings:middlewares/logMiddleware.mjs
Configuration parameters
- windowMs: Time window in milliseconds (default: 1 minute)
- max: Maximum number of requests per window (default: 100 requests)
- handler: Custom error handler that returns a 429 status code
With the default settings, each IP address can make up to 100 requests per minute. Exceeding this limit results in a 429 Too Many Requests error.
How it works
The rate limiter is applied through the log middleware:middlewares/logMiddleware.mjs
- Logs all incoming requests with IP, timestamp, and request details
- Checks if the IP is in the blocked list
- Applies rate limiting before passing to the next middleware
Rate limit headers
When rate limiting is active, the API includes these response headers:- X-RateLimit-Limit: Total number of requests allowed per window
- X-RateLimit-Remaining: Number of requests remaining in current window
- X-RateLimit-Reset: Timestamp when the rate limit window resets
Error response
When a client exceeds the rate limit, they receive a 429 status code:Customizing rate limits
You can customize the rate limit settings by modifying the configuration inmiddlewares/logMiddleware.mjs:
Increase the time window
Add different limits for different routes
Skip rate limiting for specific IPs
IP blocking
In addition to rate limiting, the API supports permanent IP blocking through a blocklist:config/blockedIps.mjs
Request logging
All requests are logged tologs/requests.log with the following information:
- Timestamp
- HTTP method and URL
- Client IP address
- Response status code
- User agent
- Query parameters
- Request body
Logs are appended to the file and persist across server restarts. Consider implementing log rotation for production environments.
Best practices
Set appropriate limits
Configure rate limits based on your API’s expected usage patterns. Too strict may frustrate legitimate users, too lenient may not provide adequate protection.
Monitor logs
Regularly review
logs/requests.log to identify abuse patterns or legitimate users hitting rate limits.Use different limits per route
Apply stricter limits to sensitive endpoints like authentication and looser limits for read-only endpoints.
Implement retry logic
If you’re building a client, implement exponential backoff when receiving 429 responses.
Testing rate limits
You can test rate limiting with a simple script:Next steps
File uploads
Learn how to handle file uploads
Authentication
Understand API authentication