Aplikacionet Android komunikojnë shpesh me APIs përmes rrjetit. Qasja standarde përdor biblioteka si Retrofit (REST client) dhe OkHttp, me coroutines për async, dhe JSON parsing — duke trajtuar thirrjet e rrjetit në mënyrë të pastër dhe të saktë jashtë thread-it kryesor.
Retrofit — REST client-i standard
{
: User
: User
}
api = Retrofit.Builder()
.baseUrl()
.addConverterFactory(GsonConverterFactory.create())
.build()
.create(ApiService::.java)
viewModelScope.launch {
user = api.getUser()
}
