It might be overwhelming to choose the best way to access a web service from your Android app. Maybe all you want is to parse JSON from a web service and show it in a list in your Kotlin app for Android, while still being future-proof with a library like Retrofit. As a bonus, it’d be great if you could also perform CRUD operations (create, read, update, delete) with the data.
You can choose from basic Java-style HTML requests, or go up to full-scale MVVM design patterns with the new Android Architecture Components. Your source code will look entirely different depending on what approach you chose – so it’s important to make a good choice right at the beginning.
In this article, I’ll show a walk-through using many of the newest components for a modern solution:
- Retrofit v2: web service access
- Moshi: converting JSON to Kotlin data classes and back
- Kotlin Coroutine Adapter for Retrofit: handles threading for asynchronous web access
- Object declaration: for singleton patterns in Kotlin
- RecyclerView with a click adapter: showing items in a list