No more Retrofit, move to Ktor on Android

Barros
3 min readMay 9, 2022
Photo by Fahim Muntashir on Unsplash

How to say the documentation, Ktor is an asynchronous framework for creating microservices, web applications and more. It is possible to use it to create a REST Client for yours Android applications.

Before to continue, Retrofit is still a good framework to make API calls, in this article I’m just suggesting another good framework that uses Kotlin libraries.

Waiting for the stable release of KMM (Kotlin Multiplatform Mobile) it could be useful starting to use this library instead of Retrofit. Let’s see how to configure it.

Part II: Logging and Interceptor

Dependencies

First, add the following dependencies in build.gradle:

def ktor_version = '1.5.1'
implementation "io.ktor:ktor-client-json:$ktor_version"
implementation "io.ktor:ktor-client-serialization-jvm:$ktor_version"
implementation "io.ktor:ktor-client-android:$ktor_version"

Also, you have to add Kotlin serialization library, adding in your classpath:

buildscript {
ext.kotlin_version = '1.6.10'
repositories { mavenCentral() }

dependencies {
classpath "org.jetbrains.kotlin:kotlin-serialization:$kotlin_version"
}
}

And apply the plugin:

plugins {
id…

--

--

Responses (6)