
Android Retrofit
- 388 installs
- 910 repo stars
- Updated July 27, 2026
- new-silvermoon/awesome-android-agent-skills
android-retrofit is an Android agent skill that wires clients to REST APIs using Retrofit with typed endpoints, serializers, interceptors, and error handling for developers who need production-grade Kotlin networking.
About
android-retrofit is an expert guidance skill from awesome-android-agent-skills for type-safe HTTP in Android using Retrofit. It covers service interface definitions, dynamic URL paths with @Path, query parameters with @Query and @QueryMap, Kotlin coroutines integration, OkHttp configuration, and Hilt dependency injection following 2025 Android practices. Developers use it when implementing network layers that need interceptors, serializers, and structured error handling instead of ad hoc URL connections. Reach for android-retrofit when building or refactoring an Android app's REST client, especially with modern DI and coroutine call patterns.
- Typed REST interfaces
- OkHttp interceptors
- JSON serialization setup
- Error and timeout handling
- Repository API wiring
Android Retrofit by the numbers
- 388 all-time installs (skills.sh)
- +11 installs in the week ending Aug 4, 2026 (Skillselion tracking)
- Ranked #337 of 1,039 Mobile Development skills by installs in the Skillselion catalog
- Data as of Aug 4, 2026 (Skillselion catalog sync)
npx skills add https://github.com/new-silvermoon/awesome-android-agent-skills --skill android-retrofitAdd your badge
Show developers this skill is listed on Skillselion. Paste this into your README.
| Installs | 388 |
|---|---|
| repo stars | ★ 910 |
| Last updated | July 27, 2026 |
| Repository | new-silvermoon/awesome-android-agent-skills ↗ |
How do you set up Retrofit for Android REST APIs?
Wire Android clients to REST APIs using Retrofit with typed endpoints, serializers, interceptors, and error handling for production networking.
Who is it for?
Android developers implementing or refactoring Kotlin REST clients with Retrofit, coroutines, OkHttp, and Hilt in production apps.
Skip if: iOS or React Native networking, gRPC-only backends, or projects standardized on Ktor client without Retrofit.
When should I use this skill?
The user implements Android HTTP with Retrofit, OkHttp interceptors, coroutines, dynamic URLs, or Hilt network modules.
What you get
Retrofit service interfaces, OkHttp client configuration, coroutine call adapters, Hilt modules, and typed error handling for API responses.
- Retrofit service interfaces
- OkHttp client setup
- Hilt network modules
Files
Android Networking with Retrofit
Instructions
When implementing network layers using Retrofit, follow these modern Android best practices (2025).
1. URL Manipulation
Retrofit allows dynamic URL updates through replacement blocks and query parameters.
- Dynamic Paths: Use
{name}in the relative URL and@Path("name")in parameters. - Query Parameters: Use
@Query("key")for individual parameters. - Complex Queries: Use
@QueryMap Map<String, String>for dynamic sets of parameters.
interface SearchService {
@GET("group/{id}/users")
suspend fun groupList(
@Path("id") groupId: Int,
@Query("sort") sort: String?,
@QueryMap options: Map<String, String> = emptyMap()
): List<User>
}2. Request Body & Form Data
You can send objects as JSON bodies or use form-encoded/multipart formats.
- @Body: Serializes an object using the configured converter (JSON).
- @FormUrlEncoded: Sends data as
application/x-www-form-urlencoded. Use@Field. - @Multipart: Sends data as
multipart/form-data. Use@Part.
interface UserService {
@POST("users/new")
suspend fun createUser(@Body user: User): User
@FormUrlEncoded
@POST("user/edit")
suspend fun updateUser(
@Field("first_name") first: String,
@Field("last_name") last: String
): User
@Multipart
@PUT("user/photo")
suspend fun uploadPhoto(
@Part("description") description: RequestBody,
@Part photo: MultipartBody.Part
): User
}3. Header Manipulation
Headers can be set statically for a method or dynamically via parameters.
- Static Headers: Use
@Headers. - Dynamic Headers: Use
@Header. - Header Maps: Use
@HeaderMap. - Global Headers: Use an OkHttp Interceptor.
interface WidgetService {
@Headers("Cache-Control: max-age=640000")
@GET("widget/list")
suspend fun widgetList(): List<Widget>
@GET("user")
suspend fun getUser(@Header("Authorization") token: String): User
}4. Kotlin Support & Response Handling
When using suspend functions, you have two choices for return types:
1. Direct Body (`User`): Returns the deserialized body. Throws HttpException for non-2xx responses. 2. `Response<User>`: Provides access to the status code, headers, and error body. Does NOT throw on non-2xx results.
@GET("users")
suspend fun getUsers(): List<User> // Throws on error
@GET("users")
suspend fun getUsersResponse(): Response<List<User>> // Manual check5. Hilt & Serialization Configuration
Provide your Retrofit instances as singletons in a Hilt module.
@Module
@InstallIn(SingletonComponent::class)
object NetworkModule {
@Provides
@Singleton
fun provideJson(): Json = Json {
ignoreUnknownKeys = true
coerceInputValues = true
}
@Provides
@Singleton
fun provideOkHttpClient(): OkHttpClient = OkHttpClient.Builder()
.addInterceptor(HttpLoggingInterceptor().apply { level = HttpLoggingInterceptor.Level.BODY })
.connectTimeout(30, TimeUnit.SECONDS)
.build()
@Provides
@Singleton
fun provideRetrofit(okHttpClient: OkHttpClient, json: Json): Retrofit = Retrofit.Builder()
.baseUrl("https://api.github.com/")
.client(okHttpClient)
.addConverterFactory(json.asConverterFactory("application/json".toMediaType()))
.build()
}6. Error Handling in Repositories
Always handle network exceptions in the Repository layer to keep the UI state clean.
class GitHubRepository @Inject constructor(private val service: GitHubService) {
suspend fun getRepos(username: String): Result<List<Repo>> = runCatching {
// Direct body call throws HttpException on 4xx/5xx
service.listRepos(username)
}.onFailure { exception ->
// Handle specific exceptions like UnknownHostException or SocketTimeoutException
}
}7. Checklist
- [ ] Use
suspendfunctions for all network calls. - [ ] Prefer
Response<T>if you need to handle specific status codes (e.g., 401 Unauthorized). - [ ] Use
@Pathand@Queryinstead of manual string concatenation for URLs. - [ ] Configure
OkHttpClientwith logging (for debug) and sensible timeouts. - [ ] Map API DTOs to Domain models to decouple layers.
Related skills
FAQ
What Retrofit patterns does android-retrofit cover?
android-retrofit covers service definitions, dynamic paths with @Path, @Query and @QueryMap parameters, Kotlin coroutines, OkHttp configuration, interceptors, serializers, error handling, and Hilt integration for Android REST clients.
Does android-retrofit target modern Android stacks?
android-retrofit follows 2025 Android networking best practices in awesome-android-agent-skills, emphasizing type-safe Retrofit interfaces with coroutines, OkHttp, and Hilt rather than legacy AsyncTask patterns.