Overview
The Football Kit Archive API implements rate limiting to protect against abuse and ensure fair usage for all users. Rate limits are applied per IP address and are enforced through middleware.Default Rate Limit
By default, the API allows:- 100 requests per hour per IP address
- Rate limit window: 1 hour (3600 seconds)
core/middleware.py:32-38:
Configuration
Custom Rate Limit
Configure the rate limit in your Django settings:Environment Variable
You can also set the rate limit via environment variable:Examples
How It Works
IP-Based Tracking
Rate limits are tracked per client IP address:Cache-Based Storage
Rate limit counters are stored in Django’s cache system:Rolling Window
The rate limit uses a rolling 1-hour window. The counter resets after 3600 seconds:Rate Limit Response
When the rate limit is exceeded, the API returns: Status Code:403 Forbidden
Response:
core/middleware.py:70-71:
Error Response Format
The error handler infkapi/api.py:247-248 formats rate limit errors:
Handling Rate Limits
Exponential Backoff
Implement exponential backoff when rate limited:Check Rate Limit Status
Monitor your usage by tracking response headers (if implemented) or by counting requests:JavaScript Example
IP Whitelisting
Exempt specific IP addresses from rate limiting:core/middleware.py:41-44:
Proxy Configuration
X-Forwarded-For Header
If your API is behind a proxy or load balancer, enableX-Forwarded-For header trust:
Testing Rate Limits
Simple Test Script
Python Test Script
Best Practices
For API Consumers
- Implement Retry Logic: Use exponential backoff when rate limited
- Track Your Usage: Monitor request counts to avoid hitting limits
- Batch Requests: Use bulk endpoints when available (e.g.,
/api/kits/bulk) - Cache Responses: Cache API responses locally to reduce request volume
- Handle 403 Errors: Always check for rate limit errors and wait before retrying
For API Administrators
- Monitor Usage: Track API metrics to identify abuse patterns
- Adjust Limits: Increase limits for trusted users or applications
- Use Whitelisting: Exempt internal services from rate limiting
- Set Up Alerts: Get notified when users hit rate limits frequently
- Document Limits: Clearly communicate rate limits to API users
Monitoring Rate Limit Usage
Check API metrics to see rate limit statistics:403 status codes indicate rate limit violations.
Related Documentation
Error Handling
Learn how to handle rate limit errors
Authentication
Combine rate limiting with API authentication