Learn about HTTP, JSON, REST and all the other cool and important abbreviations in the world of networking!
Implement the Retrofit library in Android, add interceptors, parsers, and Kotlin Coroutines.
Consider adding these to Result.kt for even more simplified code:
// full combo
fun Result.listen(onSuccess:(data:T)->Unit, onFailure: (err:Throwable?)->Unit){
if(this is Success) onSuccess(this.data)
else if(this is Failure) onFailure(this.error)
}
// or each individually
fun <T: Any> Result.onSuccess(onSuccess: (data: T) β Unit):Result{
if(this is Success) onSuccess(data)
return this
}
fun <T:Any> Result.onFailure(onFailure: (err: Throwable?) β Unit):Result{
if(this is Failure) onFailure(error)
return this
}
There are a few pieces of content we have about Kotlin Flow, but not really about Flow for networking.
IMO, we shouldnβt be using Flow for networking requests, as those are mostly one-off and basic coroutines are good enough. Iβd rather connect the Flow to the DB (Room e.g.) and then listen to changes there.