← Back to list

api-patterns
by NaoyaTakashima
⭐ 0🍴 0📅 Jan 10, 2026
SKILL.md
name: api-patterns description: REST API design patterns, authentication, and error handling for this SaaS application allowed-tools: Read, Grep, Glob
API Patterns
Authentication
JWT Token Structure
interface JWTPayload {
sub: string; // User ID
email: string;
role: 'user' | 'admin';
iat: number;
exp: number;
}
Auth Middleware
// Always use authMiddleware for protected routes
import { authMiddleware } from '@/middleware/auth';
router.get('/protected', authMiddleware, handler);
Error Handling
Standard Error Codes
| Code | HTTP Status | Description |
|---|---|---|
| AUTH_REQUIRED | 401 | Missing or invalid token |
| FORBIDDEN | 403 | Insufficient permissions |
| NOT_FOUND | 404 | Resource not found |
| VALIDATION_ERROR | 400 | Invalid request body |
| RATE_LIMITED | 429 | Too many requests |
| INTERNAL_ERROR | 500 | Server error |
Error Response Format
{
"error": {
"code": "VALIDATION_ERROR",
"message": "Email is required",
"details": { "field": "email" }
}
}
Pagination
Request
GET /api/users?page=1&limit=20&sort=createdAt&order=desc
Response
{
"data": [...],
"meta": {
"page": 1,
"limit": 20,
"total": 150,
"totalPages": 8
}
}
Rate Limiting
- Authenticated: 1000 requests/hour
- Unauthenticated: 100 requests/hour
- Endpoint-specific limits in
src/config/rateLimit.ts
Validation
Use Zod for all request validation:
import { z } from 'zod';
const createUserSchema = z.object({
email: z.string().email(),
name: z.string().min(2).max(100),
password: z.string().min(8),
});
Score
Total Score
60/100
Based on repository quality metrics
✓SKILL.md
SKILL.mdファイルが含まれている
+20
✓LICENSE
ライセンスが設定されている
+10
○説明文
100文字以上の説明がある
0/10
○人気
GitHub Stars 100以上
0/15
○最近の活動
3ヶ月以内に更新がある
0/10
○フォーク
10回以上フォークされている
0/5
✓Issue管理
オープンIssueが50未満
+5
✓言語
プログラミング言語が設定されている
+5
○タグ
1つ以上のタグが設定されている
0/5
Reviews
💬
Reviews coming soon