スキル一覧に戻る
NaoyaTakashima

api-patterns

by NaoyaTakashima

0🍴 0📅 2026年1月10日
GitHubで見るManusで実行

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

CodeHTTP StatusDescription
AUTH_REQUIRED401Missing or invalid token
FORBIDDEN403Insufficient permissions
NOT_FOUND404Resource not found
VALIDATION_ERROR400Invalid request body
RATE_LIMITED429Too many requests
INTERNAL_ERROR500Server 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),
});

スコア

総合スコア

60/100

リポジトリの品質指標に基づく評価

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

レビュー

💬

レビュー機能は近日公開予定です