Skip to content

Commit

Permalink
feat: added HTTP 429 response doc if option is enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
TeKrop committed Jul 1, 2024
1 parent 3379497 commit 4e43dac
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 2 deletions.
1 change: 1 addition & 0 deletions .env.dist
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ APP_BASE_URL=https://overfast-api.tekrop.fr
LOG_LEVEL=info
MAX_CONCURRENT_REQUESTS=5
STATUS_PAGE_URL=
TOO_MANY_REQUESTS_RESPONSE=false

# Redis
REDIS_CACHING_ENABLED=true
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@


## [Live instance](https://overfast-api.tekrop.fr)
The live instance is restricted to **30 req/s** (a shared limit across all endpoints). If you require more, consider hosting your own instance on a server 👍
The live instance is restricted to **30 req/s** per IP (a shared limit across all endpoints). If you require more, consider hosting your own instance on a server 👍

- Live instance (Redoc documentation) : https://overfast-api.tekrop.fr/
- Swagger UI : https://overfast-api.tekrop.fr/docs
Expand Down
4 changes: 4 additions & 0 deletions app/common/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@
"description": "Blizzard Server Error",
},
}
if settings.too_many_requests_response:
routes_responses[status.HTTP_429_TOO_MANY_REQUESTS] = {
"description": "Rate Limit Error",
}

# List of players used for testing
players_ids = [
Expand Down
4 changes: 4 additions & 0 deletions app/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ class Settings(BaseSettings):
# Optional, status page URL if you have any to provide
status_page_url: str | None = None

# Enable this option if you're using a reverse proxy to handle rate limits
# in order to indicate HTTP 429 as possible response from the API in doc
too_many_requests_response: bool = True

############
# REDIS CONFIGURATION
############
Expand Down
8 changes: 7 additions & 1 deletion app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,14 @@ async def lifespan(_: FastAPI): # pragma: no cover
reverse proxy and **Redis** for caching. Its tailored caching mechanism significantly
reduces calls to Blizzard pages, ensuring swift and precise data delivery to users.
This live instance is restricted to **30 req/s** (a shared limit across all endpoints).
{
"""
This live instance is restricted to **30 req/s** per IP (a shared limit across all endpoints).
If you require more, consider hosting your own instance on a server 👍
"""
if settings.too_many_requests_response
else ""
}
In player career statistics, various conversions are applied for ease of use:
- **Duration values** are converted to **seconds** (integer)
Expand Down

0 comments on commit 4e43dac

Please sign in to comment.