A client-facing dashboard component for monitoring API rate limit status and usage in real-time.
- Real-time Status Monitoring: Displays current rate limit usage with visual progress bars
- Health Indicators: Status badges showing OK, Warning, or Critical states
- Endpoint Usage Breakdown: Table view of individual endpoint usage
- Auto-refresh: Optional automatic polling with configurable interval
- Responsive Design: Fully mobile-responsive interface
- Smart Alerts: Context-aware alerts based on usage thresholds
- Plan Details: Shows current tier, reset time, and time remaining
- Help Section: Built-in tips for optimizing API usage
Located in src/components/RateLimitDashboard.tsx
import RateLimitDashboard from '@site/src/components/RateLimitDashboard';
export default function MyPage() {
return <RateLimitDashboard />;
}A dedicated page showing the full dashboard at /rate-limits.
The component expects rate limit status data with the following structure:
interface RateLimitStatus {
tier: string; // e.g., "Pro", "Enterprise"
requestsLimit: number; // Total requests in period
requestsUsed: number; // Requests already used
requestsRemaining: number; // Requests available
resetTime: string; // ISO 8601 date string
resetTimestamp: number; // Unix timestamp (ms)
percentageUsed: number; // 0-100
endpoints: EndpointUsage[]; // Per-endpoint usage
}
interface EndpointUsage {
path: string; // e.g., "/api/transactions"
method: string; // e.g., "GET", "POST"
requestsUsed: number; // Requests used for this endpoint
limit: number; // Limit for this endpoint
}To connect to a real API, modify DEMO_MODE constant in RateLimitDashboard.tsx:
const DEMO_MODE = false;The component will then fetch from /api/rate-limit-status with the following:
const response = await fetch('/api/rate-limit-status', {
method: 'GET',
headers: {
'Authorization': `Bearer ${localStorage.getItem('api_token')}`,
'Content-Type': 'application/json',
},
});{
"tier": "Pro",
"requestsLimit": 5000,
"requestsUsed": 1250,
"requestsRemaining": 3750,
"resetTime": "2024-07-30T15:30:00Z",
"resetTimestamp": 1722352200000,
"percentageUsed": 25,
"endpoints": [
{
"path": "/api/transactions",
"method": "GET",
"requestsUsed": 500,
"limit": 1000
}
]
}The dashboard automatically determines status based on usage percentage:
| Usage | Status | Color | Behavior |
|---|---|---|---|
| 0-70% | OK | Green | No warnings, normal operation |
| 70-90% | Warning | Orange | Optimization suggestions |
| 90%+ | Critical | Red | Urgent action recommended |
Edit constants in RateLimitDashboard.tsx:
// Polling interval in milliseconds
const POLLING_INTERVAL = 30000; // 30 seconds
// Use mock data (true) or real API (false)
const DEMO_MODE = true;All styles are in src/css/custom.css under the /* ── Rate Limit Dashboard ──────────────────────────────────────────────────── */ section.
--ifm-color-primary: Primary green--ifm-color-primary-dark: Darker green--ifm-color-emphasis-*: Various emphasis levels--ifm-background-*: Background colors--ifm-font-color-base: Text color
.rate-limit-dashboard: Main container.rate-limit-card: Overview cards.rate-limit-table: Endpoint usage table.rate-limit-alert: Alert messages.rate-limit-progress-bar: Usage progress visualization
Displays usage with visual bar and percentage.
<ProgressBar
used={123}
limit={1000}
status="ok"
/>Shows health status indicator.
<StatusBadge status="warning" />
// Output: ● WarningContextual alert message.
<Alert alert={{
level: 'critical',
message: 'You have used 90% or more of your rate limit.',
timestamp: Date.now(),
}} />Table row for individual endpoint usage.
<EndpointUsageRow endpoint={endpointData} />Users can enable/disable automatic status polling via checkbox. When enabled, data refreshes every 30 seconds.
"Refresh" button allows immediate data fetch.
Shows when data was last fetched with human-readable timestamp.
Built-in help content with best practices:
- Use webhooks instead of polling
- Batch requests
- Implement caching
- Use exponential backoff
- Monitor usage patterns
- Desktop: 2-column cards, full table
- Tablet (≤768px): Single-column cards, condensed table
- Mobile (≤480px): Stacked layout, minimal padding
- Semantic HTML structure
- ARIA labels on interactive elements
- Color-coded status is supplemented with text labels
- Keyboard navigation support
- Clear loading and error states
- Displays error message if API fetch fails
- "Try Again" button to retry failed requests
- Graceful fallback with meaningful error text
- Spinner animation while fetching data
- Disabled refresh button during loading
- "Updating…" text on button
By default, the component runs in DEMO_MODE = true, which:
- Generates realistic mock data
- Simulates 500ms fetch delay
- Includes various usage scenarios
- Useful for testing and development
To test with different data, modify the generateMockStatus() function.
import RateLimitDashboard from '@site/src/components/RateLimitDashboard';
export default function DocPage() {
return (
<div>
<h1>Monitor Your Usage</h1>
<RateLimitDashboard />
</div>
);
}Access at /rate-limits (already configured in src/pages/rate-limits.tsx)
import RateLimitDashboard from '@site/src/components/RateLimitDashboard';
export default function Dashboard() {
return (
<div className="dashboard">
<RateLimitDashboard />
</div>
);
}The component is fully functional in demo mode. Test features:
- Auto-refresh: Toggle checkbox to see updates every 30 seconds
- Manual refresh: Click button to fetch new data
- Responsive: Resize window to test mobile layouts
- Alert handling: Note different alert levels based on usage
- Graphical trends (usage over time)
- Export usage data (CSV/PDF)
- Usage alerts and notifications
- Predictive rate limit exhaustion
- Integration with billing information
- Webhook event tracking
- Custom alert thresholds
- Usage forecast based on historical data
- Uses React hooks for state management
- No external UI libraries (pure CSS)
- TypeScript interfaces for type safety
- Responsive with mobile-first approach
- Accessibility-compliant design
- Performance optimized with callbacks and memoization