DEV Community

Yogesh Choudhary Paliyal
Yogesh Choudhary Paliyal

Posted on • Originally published at yogeshpaliyal.com on

Android Fast Networking with Kotlin Coroutines

Alt Text
Android Fast Networking is a great library for networking I am using since 2016, It has many features that are not available in similar networking libraries.

AFN provides direct support for RxJava but not for Coroutines, so we create by ourself

Adding AFN and Kotlin Coroutines to the project

// GSON
implementation 'com.google.code.gson:gson:2.8.6'

// Android Fast Networking
implementation 'com.amitshekhar.android:android-networking:1.0.2'

// Coroutines
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.9'

Enter fullscreen mode Exit fullscreen mode

In this project, we are using the State Management approach class Resource

The resource is a wrapper class that contains status (Loading, Success, Error), message, Data

Creating a BaseCaller, every API call will be going through this class, this is the class where the magic happens.

BaseApiModel is an API structure that is used for all APIs like, change as per requirements

{
  "status" : 200,
  "message" : "Api hit success",
  "data" : {
      "name" : "Yogesh Paliyal"
  }
}

Enter fullscreen mode Exit fullscreen mode

Top comments (0)