Android Networking: Fundamentals |

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.

This is a companion discussion topic for the original entry at

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(
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

and implemented:

remoteApi.addTask(AddTaskRequest(title, content, priority))
.onSuccess { onTaskAdded(it) }
.onFailure { onTaskAddFailed() }

1 Like

Hey @ooono!

Thanks for the comments and suggestions!

I typically prefer the base use where we deal just with values, but this is more Rx-style or future-style works, and it suits other people better!

But the community can choose what they like and thanks to your comment they get another option!


True, it’s a bit functional. Is there a course that works with network requests and kotlin flow?

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.

Here is the content I mentioned: