Android apps ધરતી APIs સાથે નેટવર્ક પર વધુ વાર સંચાર કરે છે. સ્ટાન્ડર્ડ અભિગમ Retrofit (REST client) અને OkHttp જેવી libraries, coroutines માટે async, અને JSON parsing નો ઉપયોગ કરે છે — નેટવર્ક calls ને main thread બહારથી સાફ અને યોગ્ય રીતે સંભાળે છે।
Retrofit — પ્રમાણભૂત REST client
{
: User
: User
}
api = Retrofit.Builder()
.baseUrl()
.addConverterFactory(GsonConverterFactory.create())
.build()
.create(ApiService::.java)
viewModelScope.launch {
user = api.getUser()
}
