https://kotlinlang.org logo
#multiplatform
Title
# multiplatform
a

archana 0623

04/12/2021, 6:19 AM
Can anyone help me understand how can we handle asynchronous network calls with ktor http client like adding loader and when it is either success or error then hide it and load appropriate data, with promises and observables it could be done through success or error callback but how can we achieve the same with ktor http client?
j

Joost Klitsie

04/12/2021, 7:48 AM
you should treat ktor as a simple point to get your data. How your UI reacts on it is up to you, just like any other library you might use to do the job. A simplistic approach would be: • Invoke an action that loads data (e.g. click a button) • Show loading dialog • Trigger backend call with your favourite http client (e.g. ktor) • When result is success or error, hide the loading dialog. How you get the result passed back is up to you. You can use whatever you want for it, but it will not happen magically out of the box. I suggest using this wonderful website called Google to Google your favourite platform to work on, learn about patterns to make backend calls and showing loading dialogs and then substitute the http library for ktor
🙏 1