This project is a sample app for making REST calls with OkHttp and Kotlin Coroutines.
It contains:
- Configuring your app for making REST calls by setting the internet permission
- Uses OkHttp to make a Get call
- Launches a HTTP request from a background thread using Kotlin coroutines
- Uses ViewModel and LiveData to update the UI.
For a step-by-step tutorial, please see my blog post on making REST calls with OkHttp and Kotlin coroutines.
- Cone the project from GitHub
https://github.com/justmobiledev/android-kotlin-rest-okhttp-2.git
- Build the project in AndroidStudio
- Deploy on simulator or device.
- Android Studio 4.1.1
- Android API 29
- OkHttp 4.9.0
- view model and livedata 2.2.0
- klaxon 5.0.1
- Configuring your app for making REST calls by setting the internet permission
- Use OkHttp to make a Get call
- Launch a HTTP request from a background thread using Kotlin coroutines
- Use ViewModel and LiveData to update the UI.
- Select the 'Fetch' button to launch a Get request
- The response info is displayed in the MainActivity page