When developing an Android application it is important to plan the architecture of the project. This will allow us to create good quality code and easy to maintain applications.

This article will focus on how to use Retrofit with Kotlin Coroutines to call asynchronous REST Api with MVVM architecture.

The project
We will be using the Dog CEO API 🐶 to get random puppy images, and we will be using an image loading library called Glide to display the image. Simple!

Set up a new project with Kotlin and other dependencies required:

def lifecycle_version = "2.2.0"

// ViewModel
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycle_version"

// LiveData
implementation "androidx.lifecycle:lifecycle-livedata-ktx:$lifecycle_version"

//…

Teng Tonghann

Android Engineer

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store