Android | Using Kotlin Coroutine to Perform HTTP Request using HttpUrlConnection
Long-running task such as CPU intensive work, writing a file to disk or network request should NOT run on the main thread. Android, for example, will throw a NetworkOnMainThreadException if you try to perform an HTTP reqeust on the main thread. To resolve this issue, we can use Kotlin coroutine to perform long-running task on a separate thread. This post shows how to perform a non-blocking HTTP reqest using HttpUrlConnection and Kotlin coroutine.