Skip to content
cccskills
FreePublished on GitHub

android-api-client

Retrofit + OkHttpを使用したAPIクライアント実装のベストプラクティスを提供する。「API実装」「APIクライアント」「Retrofit」「OkHttp」「ネットワーク」と言われたら使う。

The English summary is being prepared. Showing the original description.

See how to install

Files included (2)

  • SKILL.md3.3 KB
  • REFERENCE.md40.1 KB

SKILL.md (original)

Review the instructions the agent will receive before you install.

Android APIクライアント実装ガイドライン

Retrofit + OkHttpを使用したAPIクライアント実装のベストプラクティス。

クイックリファレンス

技術スタック

// Retrofit + OkHttp + Kotlinx Serialization
implementation("com.squareup.retrofit2:retrofit:2.9.0")
implementation("com.squareup.retrofit2:converter-kotlinx-serialization:2.9.0")
implementation("com.squareup.okhttp3:okhttp:4.12.0")
implementation("com.squareup.okhttp3:logging-interceptor:4.12.0")
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.6.0")

アーキテクチャ

UI Layer (ViewModel)
    ↓
Domain Layer (UseCase / Repository Interface)
    ↓
Data Layer (Repository Implementation → API Service → OkHttpClient)

API Service定義

interface ApiService {
    @GET("users")
    suspend fun getUsers(@Query("page") page: Int): List<UserDto>

    @GET("users/{id}")
    suspend fun getUser(@Path("id") userId: String): UserDto

    @POST("users")
    suspend fun createUser(@Body request: CreateUserRequest): UserDto
}

エラーハンドリング(ApiResult型)

sealed interface ApiResult<out T> {
    data class Success<T>(val data: T) : ApiResult<T>
    data class Error(val error: ApiError) : ApiResult<Nothing>
}

sealed class ApiError {
    data class HttpError(val code: Int, val message: String) : ApiError()
    data class NetworkError(val cause: Throwable) : ApiError()
    data object Unauthorized : ApiError()
    data object Timeout : ApiError()
}

安全なAPI呼び出し

suspend fun <T> safeApiCall(apiCall: suspend () -> T): ApiResult<T> {
    return try {
        ApiResult.Success(apiCall())
    } catch (e: HttpException) {
        ApiResult.Error(ApiError.HttpError(e.code(), e.message()))
    } catch (e: IOException) {
        ApiResult.Error(ApiError.NetworkError(e))
    }
}

Repository実装パターン

class UserRepositoryImpl @Inject constructor(
    private val apiService: ApiService,
    private val userMapper: UserMapper
) : UserRepository {

    override suspend fun getUser(id: String): Result<User> {
        return safeApiCall { apiService.getUser(id) }
            .map { userMapper.toDomain(it) }
            .toResult()
    }
}

含まれるセクション

  1. 基本構成 - 技術スタック、アーキテクチャ
  2. Retrofit + OkHttp構成 - API Service、OkHttpClient、カスタムInterceptor
  3. エラーハンドリング - ApiResult型、ApiError sealed class、safeApiCall
  4. Repository層との連携 - 実装パターン、DTO変換、キャッシュ戦略
  5. 認証・トークン管理 - TokenProvider、リフレッシュ付きAuthenticator
  6. OpenAPI Generator - 設定、仕様例、カスタマイズ
  7. テスタビリティ - MockWebServer、Repositoryテスト、Fake実装
  8. ベストプラクティス - 設計原則、チェックリスト、アンチパターン

詳細ガイドライン

詳細は REFERENCE.md を参照してください。

Reviews

No reviews yet. Tell others what you thought.

Comments

No login needed. Share how it worked for you, ask a question, or note where it did not run.

No comments yet. Be the first to write one.

Comments are published right away. Do not include personal information such as email addresses or phone numbers. Up to 2 URLs.

0 / 1,000 characters

This form is protected by reCAPTCHA, and the Google Privacy Policy and Terms of Service apply.

More skills from this repository

Androidプロジェクトのアーキテクチャ設計を支援。プロジェクト特性に応じてMVI/MVVM/シンプルComposeから最適なパターンを提案し、パッケージ構造の設計と既存プロジェクトの分析を行う。

The English summary is being prepared. Showing the original description.

xtone/ai_development_tools3Updated Oct 16, 2026

Firebase Crashlyticsのスタックトレースを解析し、トリアージ分類→根本原因分析→修正提案を出力するスキル。/crash-analyze コマンド、クラッシュ解析、スタックトレース分析、ANR分析、Crashlytics、クラッシュレポート、またはFirebase crashに関連するリクエストで使用される。クラッシュ対応のワークフローを標準化し、対応品質と速度を向上させる。ANR/Non-fatal/Fatal全タイプ対応。

The English summary is being prepared. Showing the original description.

xtone/ai_development_tools3Updated Oct 16, 2026

Android data layer implementation guide. Provides comprehensive patterns for Room Database (Entity, DAO, Migration), DataStore (Preferences), Repository layer design, and common pitfalls. Use when implementing local data storage, cache strategies, or data source integration in Android projects.

The English summary is being prepared. Showing the original description.

xtone/ai_development_tools3Updated Oct 16, 2026

重要: ユーザーがAndroidテスト実行をリクエストした場合、常にこのスキルを最初に使用してください。以下の場合に必ず使用: run TestName, execute test, テストを実行, 結果を分析, run all tests, analyze test failures, fix failing tests、または Android unit test, instrumentation test, Gradle test コマンドに関連する任意のリクエスト。./gradlew test や Bash コマンドを直接使用しないでください - 常にこのスキルに委譲してください。Multi-variantプロジェクト、JAVA_HOME セットアップ、一般的なテストパターンに対応しています。

The English summary is being prepared. Showing the original description.

xtone/ai_development_tools3Updated Oct 16, 2026

Jetpack ComposeでUIを実装する時に参照するコーディングガイドライン。 「Android UI」「Compose」「Jetpack」「画面実装」「UIコンポーネント」「レイアウト」と言われたら使う。 Android/Kotlin UI実装のベストプラクティス、アンチパターン、実装パターンを提供する。

The English summary is being prepared. Showing the original description.

xtone/ai_development_tools3Updated Oct 16, 2026

非同期処理のバックエンドとフロントエンドを実装する際のベストプラクティスをまとめたスキルです。非同期処理が必要なWebサービスのフロントエンドおよびバックエンドを実装する際に利用されます。

The English summary is being prepared. Showing the original description.

xtone/ai_development_tools3Updated Oct 16, 2026

See all skills by xtone

Report a problem with this skill