Android apps frequently communicate with APIs over the network. The standard approach uses libraries like Retrofit (REST client) and OkHttp, with coroutines for async, and JSON parsing — handling network calls cleanly and correctly off the main thread.
Retrofit — the standard REST client
{
: User
: User
}
api = Retrofit.Builder()
.baseUrl()
.addConverterFactory(GsonConverterFactory.create())
.build()
.create(ApiService::.java)
viewModelScope.launch {
user = api.getUser()
}
