Android API Integrator
Overview
This skill automates the multi-layer implementation required for a new API endpoint. It covers DTO creation, Retrofit service updates, Domain layer models/interfaces, and Data layer implementations (including mapping and DI).
Workflow
- •Read & Analyze:
- •Read the provided API specification (endpoint, method, request/response body).
- •Identify which module/feature it belongs to (e.g.,
feature:mypage->UserApiService,UserRepository).
- •Implement Network Layer (
core:network):- •Create/Update DTOs (Request/Response) using
@Serializable. - •Add the
@POST/@GET/@DELETEmethod to the appropriateApiServiceinterface. - •Always return
BaseResponse<T>.
- •Create/Update DTOs (Request/Response) using
- •Implement Domain Layer (
domain):- •Create/Update pure Kotlin Domain models.
- •Add the suspend function to the
Repositoryinterface.
- •Implement Data Layer (
core:data):- •Add the implementation to the
RepositoryImpl. - •Use
.getOrThrow()to handle API errors. - •Implement the mapping logic (
toDomain()) from DTO to Domain model.
- •Add the implementation to the
- •Update Hilt DI:
- •If a new
ApiServiceorRepositoryis created, ensure it's registered inNetworkModuleandDataModule.
- •If a new
- •Advanced Handling:
- •For list endpoints, consider Paging 3 implementation as shown in advanced_patterns.md.
- •For Auth APIs, implement Token post-processing using
UserPreferencesDataSource.
Key Patterns
- •BaseResponse: All Retrofit calls MUST use
BaseResponse<T>and call.getOrThrow()in the repository. - •Pure Domain: The
domainmodule must have NO Android or Network (Serialization) dependencies. - •Mapping: Data layer is responsible for mapping Network DTOs to Domain models.
Reference
- •Integration Patterns: Detailed code examples and locations.
- •Advanced Integration Patterns: Paging, Token handling, and Error handling.