-
Notifications
You must be signed in to change notification settings - Fork 523
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore: Add API Rate limiting to API documentation #2681
base: main
Are you sure you want to change the base?
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
|
📝 WalkthroughWalkthroughA new file, Changes
Possibly related PRs
Suggested labels
Suggested reviewers
Warning Rate limit exceeded@chronark has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 28 minutes and 46 seconds before requesting another review. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
🧹 Outside diff range and nitpick comments (5)
apps/www/content/glossary/api-rate-limiting.mdx (5)
102-102
: Improve key format to prevent conflictsThe current key format might lead to conflicts in a multi-tenant environment.
- key = f"{request.remote_addr}:{request.endpoint}" + key = f"rate_limit:{request.remote_addr}:{request.endpoint}"
98-115
: Add type hints and improve error handlingThe code example would benefit from type hints and better error handling for production use.
Here's an improved version:
from typing import Callable, TypeVar, Any from datetime import datetime T = TypeVar('T') def rate_limiter(max_requests: int, time_period: int) -> Callable[[Callable[..., T]], Callable[..., T]]: def decorator(f: Callable[..., T]) -> Callable[..., T]: @wraps(f) def decorated_function(*args: Any, **kwargs: Any) -> T: key = f"rate_limit:{request.remote_addr}:{request.endpoint}" try: pipe = redis_client.pipeline() pipe.get(key) pipe.incr(key, 1) pipe.expire(key, time_period) results = pipe.execute() requests = int(results[0] or 0) if requests >= max_requests: retry_after = redis_client.ttl(key) response = jsonify({ "error": "Rate limit exceeded", "retry_after_seconds": max(0, retry_after) }) response.headers['Retry-After'] = str(max(0, retry_after)) return response, 429 return f(*args, **kwargs) except redis.RedisError as e: app.logger.error(f"Redis error: {str(e)}") return jsonify({"error": "Service temporarily unavailable"}), 503 return decorated_function return decorator
66-66
: Fix grammatical issues in the documentationSeveral compound adjectives should be hyphenated when they modify a noun:
- "API Rate Limiting Concepts" → "API-Rate-Limiting Concepts"
- "rate limiting middleware" → "rate-limiting middleware"
- "Rate Limiting Strategies" → "Rate-Limiting Strategies"
- "Rate Limiting Techniques" → "Rate-Limiting Techniques"
Also, add an article before "retry":
- "when to retry" → "when to make a retry"
Also applies to: 131-131, 134-134, 142-142, 147-147
🧰 Tools
🪛 LanguageTool
[uncategorized] ~66-~66: If this is a compound adjective that modifies the following noun, use a hyphen.
Context: ...s for developers. ## Understanding API Rate Limiting Concepts API rate limiting involves re...(EN_COMPOUND_ADJECTIVE_INTERNAL)
146-148
: Enhance the REST API headers sectionThe headers section should include a complete list of standard rate limit headers and their usage examples.
Consider adding these standard headers:
X-RateLimit-Reset
: Timestamp when the rate limit will resetX-RateLimit-Policy
: Description of the rate limit policyRateLimit-*
: Standardized headers as per draft RFCExample:
X-RateLimit-Limit: 100 X-RateLimit-Remaining: 95 X-RateLimit-Reset: 1640995200 Retry-After: 60🧰 Tools
🪛 LanguageTool
[grammar] ~147-~147: Before the countable noun ‘to’ an article or a possessive pronoun is necessary.
Context: ...e this header to inform clients when to retry after hitting a rate limit. - **Token B...(IN_NN_CC_VBG)
150-150
: Add a troubleshooting sectionConsider adding a troubleshooting section that covers common rate limiting issues and their solutions:
- Rate limit exceeded in microservices architecture
- Handling rate limits in distributed systems
- Debugging rate limit configuration issues
- Common client-side handling patterns
Would you like me to help draft this section?
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (1)
apps/www/content/glossary/api-rate-limiting.mdx
(1 hunks)
🧰 Additional context used
🪛 LanguageTool
apps/www/content/glossary/api-rate-limiting.mdx
[uncategorized] ~66-~66: If this is a compound adjective that modifies the following noun, use a hyphen.
Context: ...s for developers. ## Understanding API Rate Limiting Concepts API rate limiting involves re...
(EN_COMPOUND_ADJECTIVE_INTERNAL)
[uncategorized] ~131-~131: If this is a compound adjective that modifies the following noun, use a hyphen.
Context: ...s. 2. express-rate-limit: A Node.js rate limiting middleware for Express applications. 3....
(EN_COMPOUND_ADJECTIVE_INTERNAL)
[uncategorized] ~134-~134: If this is a compound adjective that modifies the following noun, use a hyphen.
Context: ... frequency to resources. ## Cloudflare Rate Limiting Strategies Cloudflare provides advance...
(EN_COMPOUND_ADJECTIVE_INTERNAL)
[uncategorized] ~142-~142: If this is a compound adjective that modifies the following noun, use a hyphen.
Context: ...ype of rate limit trigger. ## REST API Rate Limiting Techniques REST APIs can implement rat...
(EN_COMPOUND_ADJECTIVE_INTERNAL)
[grammar] ~147-~147: Before the countable noun ‘to’ an article or a possessive pronoun is necessary.
Context: ...e this header to inform clients when to retry after hitting a rate limit. - **Token B...
(IN_NN_CC_VBG)
- url: https://www.example.com/api-rate-limiting | ||
title: API Rate Limiting — Everything You Need to Know | ||
- url: https://www.example.com/rate-limiting-best-practices | ||
title: Best Practices and Configurations for Implementing Rate Limiting in APIs | ||
- url: https://www.example.com/rate-limiting-guide | ||
title: Everything You Need to Know About Rate Limiting for APIs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Replace example.com URLs with actual resource links
The recommended reading section contains placeholder URLs using example.com. These should be replaced with actual, valid resource links to provide real value to readers.
Consider replacing these with links to reputable sources like:
- AWS documentation on API rate limiting
- Microsoft Azure API management documentation
- Google Cloud API design guides
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like the humans are having a chat. I'll hop back into my burrow for now. If you need me again, just tag @coderabbitai in a new comment, and I'll come hopping out!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Noted
Thank you for following the naming conventions for pull request titles! 🙏 |
- url: https://www.example.com/api-rate-limiting | ||
title: API Rate Limiting — Everything You Need to Know | ||
- url: https://www.example.com/rate-limiting-best-practices | ||
title: Best Practices and Configurations for Implementing Rate Limiting in APIs | ||
- url: https://www.example.com/rate-limiting-guide | ||
title: Everything You Need to Know About Rate Limiting for APIs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
app.run() | ||
``` | ||
|
||
## GitHub Resources for API Rate Limiting |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we expect the user to search for these?
can we use links instead?
@p6l-richard
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Noting:
- exclude GitHub (or any particular) Resources from content generation
- rename the "recommended reading" section from takeaways into "recommended resources" and have it include github link(s) if fitting
This PR adds the API Rate limiting.mdx file to the API documentation.
Summary by CodeRabbit