Posts

Showing posts with the label retrofit

Using RxJava, Retrofit in Android - Kotlin

Image
Introduction: Reactive Programming is a programming paradigm that’s concerned with data streams and propagation of change. The reactive model listens to changes in the event and runs the relevant code accordingly. RxJava is a Java based implementation of Reactive Programming. Whereas, RxAndroid is specific to Android platform which utilises some classes on top of the RxJava library. Classes and Concepts: There are 3 main components in RxJava. (i) Observable - It emits a stream of data or events. i.e., a class that can be used to perform some action, and publish the result. (ii) Observer - It receivers the events or data and acts upon it. i.e. a class that waits and watches the Observable, and reacts whenever the Observable publishes results. It have 4 interface methods to know the different states of Observable, as follows:         onSubscribe() - invoked when the Observer is subscribed.         onNext() - invoked when t...

Retrofit Integration in Android - Kotlin

Image
Retrofit is a Networking library, which is faster to use and easier to develop. Let’s see how to integrate Retrofit in Android with Kotlin. If you'd like to integrate RxJava as well, you can check here . 1. Configure: Include the following in app-level build.gradle. build.gradle compile "com.squareup.retrofit2:retrofit:2.3.0" compile "com.squareup.retrofit2:converter-gson:2.3.0" Include internet permission in Manifest file. AndroidManifest.xml <uses-permission android:name="android.permission.INTERNET" /> 2. Preparing Helper classes: ApiInterface.kt interface ApiInterface {    @POST("get_users_detail") // Your url    fun getUser(@Body requestBody: RequestBody): Call<UserResponse> } Model classes:                      Response from Retrofit will be stored in POJO classes dir...