← スキル一覧に戻る

standardizing-api-integration
by Mkas08
⭐ 0🍴 0📅 2026年1月23日
SKILL.md
name: standardizing-api-integration description: Standardize API communication, error handling, and authentication. Use when building new API services or debugging network issues.
API Integration Standards
When to use this skill
- When creating new API services or endpoints.
- When setting up authentication flows.
- When debugging network errors or timeout issues.
- When configuring the HTTP client (Axios, Dio, Fetch).
API Client Setup
- Library: Use a robust HTTP client like Axios (JS/TS) or Dio (Flutter). Avoid raw
fetchfor complex apps. - Configuration:
- Base URL: Always load from environment variables (
process.env.API_URLorConfig.apiUrl). - Timeouts: Set reasonable connection and receive timeouts (e.g., 10s/30s).
- Interceptors: Use interceptors for:
- Attaching Auth headers (
Authorization: Bearer ...). - Logging requests/responses (in debug mode).
- Global error handling.
- Attaching Auth headers (
- Base URL: Always load from environment variables (
Request Handling
- Service Layer: Centralize all API calls in
/services(e.g.,AuthService.ts,UserService.ts). UI components should never call the API client directly. - Typed Responses: Define strict TypeScript interfaces for all API response payloads. Do not use
any. - Retry Logic: Implement retry mechanisms for transient network errors (e.g., 503 Service Unavailable, timeout).
- Cancellation: Support request cancellation (AbortController) to prevent race conditions on unmount.
Error Handling
Define a standardized error interface to handle exceptions consistently across the app.
interface ApiError {
message: string;
status: number;
code: string; // e.g., 'USER_NOT_FOUND'
details?: any;
}
// Example Generic Handler
const handleApiError = (error: any): ApiError => {
if (isAxiosError(error)) {
// Map HTTP error to domain error
return {
message: error.response?.data?.message || 'Unknown error',
status: error.response?.status || 500,
code: error.response?.data?.code || 'SERVER_ERROR'
};
}
return { message: error.message, status: 0, code: 'UNKNOWN' };
};
Authentication
- Storage: Store tokens securely.
- Mobile: Use OS keychain (Expo SecureStore / Flutter SecureStorage).
- Web: Use HttpOnly cookies (preferred) or Secure LocalStorage.
- lifecycle:
- Auto-Refresh: Intercept 401 responses to refresh the access token transparently.
- Logout: Clear all local tokens and state on logout.
スコア
総合スコア
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
レビュー
💬
レビュー機能は近日公開予定です