Android-Apps kommunizieren häufig über das Netzwerk mit APIs. Der Standard-Ansatz nutzt Bibliotheken wie Retrofit (REST-Client) und OkHttp, mit Coroutines für asynchrone Operationen und JSON-Parsing — um Netzwerk-Aufrufe sauber und korrekt außerhalb des Hauptthreads zu handhaben.
Retrofit — der Standard-REST-Client
{
: User
: User
}
api = Retrofit.Builder()
.baseUrl()
.addConverterFactory(GsonConverterFactory.create())
.build()
.create(ApiService::.java)
viewModelScope.launch {
user = api.getUser()
}
