Using Retrofit with Kotlin Coroutines MVVM in Android to Collect Data From The New York Times APIs

This repository contains a sample app that implements MVVM architecture using Kotlin, ViewModel, Retrofit, Coroutines and etc to get popular articles provided by NY APIs and set it in recyclerview with custom adapter.



  1. Where to find The New York Times article metadata
  2. How to request article metadata from The New York Times

The New York Times offers a developer network consisting of several APIs to let non-employees request articles and metadata from them, which is super convenient for this analysis



  1. Register a new app in your developer’s account.
  2. Click on your e-mail address in the upper-right corner.
  3. Select Apps in the drop-down menu that appears.
  4. Select +NEW APP on your Apps page.
  5. Enter any name and description.
  6. Activate the Archive API.
  7. Select Create.

Take note of your just registered app’s API key. This is the only piece of information we need to get data from The New York Times, and we will need it soon.





The app has following packages:

  1. data: It contains all the data accessing and manipulating components.
  2. ui: View classes along with their corresponding ViewModel.
  3. utils: Utility classes.

Unit Test: Unit-test for ApiHelper , Repository and ViewModel which uses Kotlin Coroutines.

  1. ViewModelTest Code
  2. RepositoryTest Code
  3. ApiHelperTest Code

Reference resources:

  1. Coroutines: Check here
  2. Retrofit: Check here