πŸ”Œ APIs, Databases, and Backend Integration

Retrofit vs Ktor Client for Android

Retrofit is the long-standing default for Android networking. Ktor Client is JetBrains' multiplatform HTTP client. Both work well. The right choice depends mostly on whether your networking code must run beyond Android.

✍️ Yunok Tech πŸ“… Updated ⏱ 3 min read 🎯 Intermediate
On this page
  1. The same endpoint in both
  2. Comparison
  3. Testing with Ktor's MockEngine
  4. Real scenarios
  5. Common mistakes
  6. Frequently asked questions
  7. Conclusion

If your project is Android-only, Retrofit is a safe, well-understood default. If you share networking with iOS through Kotlin Multiplatform, Ktor Client is the natural fit. Everything else in this comparison refines that headline.

The same endpoint in both

RetrofitKotlin
interface GithubApi {
    @GET("users/{user}/repos")
    suspend fun repos(@Path("user") user: String, @Query("per_page") perPage: Int = 30): List<RepoDto>
}
// val api = retrofit.create(GithubApi::class.java); api.repos("android")
Ktor ClientKotlin
val client = HttpClient(OkHttp) {                          // engine: OkHttp on Android
    install(ContentNegotiation) { json(Json { ignoreUnknownKeys = true }) }
    install(HttpTimeout) { requestTimeoutMillis = 15_000 }
    defaultRequest { url("https://api.github.com/") }
    expectSuccess = true                                    // throw on non-2xx
}

class GithubApi(private val client: HttpClient) {
    suspend fun repos(user: String, perPage: Int = 30): List<RepoDto> =
        client.get("users/$user/repos") { parameter("per_page", perPage) }.body()
}

Comparison

AspectRetrofitKtor Client
StyleDeclarative annotated interfacesImperative DSL (request builders)
PlatformsJVM and AndroidKotlin Multiplatform: Android, iOS, JVM, JS, native
TransportOkHttpPluggable engines (OkHttp, CIO, Darwin on iOS…)
SerializationConverters (kotlinx.serialization, Moshi…)ContentNegotiation plugin (kotlinx.serialization)
Cross-cutting concernsOkHttp interceptors and authenticatorsPlugins (Auth, Logging, HttpTimeout, retry)
TestingMockWebServer, fakesMockEngine, fakes
Ecosystem on AndroidVery mature, huge community knowledgeMature and growing, strong in KMP
Choosing between Retrofit and Ktor Client If networking code must be shared with iOS or other platforms, choose Ktor Client. If Android-only and the team already uses Retrofit, keep Retrofit. If Android-only and starting fresh, either works; choose Retrofit for familiarity or Ktor for future multiplatform plans. Share networking with iOS? yesno Ktor Clientin KMP shared module Retrofit (default)or Ktor if KMP is planned
Platform scope decides most cases. Team familiarity decides the rest.

Testing with Ktor's MockEngine

GithubApiTest.ktKotlin
@Test
fun `parses repos`() = runTest {
    val engine = MockEngine { request ->
        assertEquals("/users/android/repos", request.url.encodedPath)
        respond("""[{"id":1,"name":"nowinandroid"}]""", headers = headersOf(HttpHeaders.ContentType, "application/json"))
    }
    val client = HttpClient(engine) { install(ContentNegotiation) { json(Json { ignoreUnknownKeys = true }) } }
    val repos = GithubApi(client).repos("android")
    assertEquals("nowinandroid", repos.single().name)
}

Real scenarios

Android-only app with existing Retrofit code

Keep Retrofit. Migration cost brings no user benefit.

New KMP app (Android + iOS)

Ktor in commonMain with the OkHttp engine on Android and the Darwin engine on iOS.

Gradual KMP adoption

Keep Retrofit in the Android app, and write new shared modules with Ktor behind a repository interface.

Common mistakes

  • Creating a new HttpClient per request in Ktor. Create one and share it, then close it when it's no longer needed.
  • Forgetting expectSuccess = true (or manual status checks) in Ktor, which silently parses error bodies.
  • Mixing both clients for the same API, which doubles configuration (auth, timeouts, logging).

Frequently asked questions

Is Ktor slower than Retrofit on Android?

With the OkHttp engine, both use the same transport. Differences are rarely significant compared with network latency.

Can Retrofit be used in Kotlin Multiplatform?

Retrofit targets the JVM and Android. For shared code that also runs on iOS, use a multiplatform client like Ktor.

Which is easier for beginners?

Retrofit's annotated interfaces are very approachable, and most Android tutorials use them. Ktor's DSL is also straightforward once you know coroutines.

Conclusion

Retrofit remains an excellent default for Android-only apps. Ktor Client is the better fit when networking must be shared across platforms with Kotlin Multiplatform. Either way, hide the client behind repositories so the choice stays reversible.

Next step: master the layer underneath Retrofit with OkHttp Interceptors Explained.

Official references

πŸ“± Apps built by Yunok Tech

Real Android apps on Google Play, free to download.

See all our apps β†’

Ready to build real Android applications?

Networking, persistence and offline sync are where real apps get complicated. Practise building a data layer that handles slow networks, failures and caching, not just the happy path.

Move beyond theory and strengthen your Android development skills with Yunoktech's Android course. Learn core concepts, practical implementation, modern Android development techniques, and the reasoning behind building maintainable applications.

Explore the Android course and take your next step as an Android developer.

Share: LinkedIn X / Twitter WhatsApp