retrofit2-kotlin

Additional

Language
Kotlin
Version
1.0.0 (Jan 15, 2018)
Created
Jan 15, 2018
Updated
Jan 15, 2018 (Retired)
Owner
Alfian Akmal Hanantio (amalhanaja)
Contributor
Alfian Akmal Hanantio (amalhanaja)
1
Activity
Badge
Generate
Download
Source code

Retrofit Kotlin

A Kotlin DSL Language for Retrofit 2

Usage

  • Building Retrofit Instance
        val retrofit = retrofit {
            baseUrl = url
            this.client = client
            converterFactories = arrayListOf(GsonConverterFactory.create(gson))
            callAdapterFactories = arrayListOf(RxJava2CallAdapterFactory.create())
        }
  • Creating Retrofit Service :
    interface Service {
        @GET("/")
        fun body(): Call<String>

        @GET("/")
        fun response(): Call<Response<String>>
    }    
    
    val service: Service = service = createRetrofitService {
            baseUrl = "<<YOUR_BASE_URL>>"
            client = OkHttpClient()
            converterFactories = arrayListOf(GsonConverterFactory.create(gson))
            callAdapterFactories = arrayListOf(RxJava2CallAdapterFactory.create())
    }

OR

You can create Retrofit service using existing Retrofit Instance :

 val service: Service = retrofit {
            baseUrl = url
            this.client = client
            converterFactories = arrayListOf(GsonConverterFactory.create(gson))
            callAdapterFactories = arrayListOf(RxJava2CallAdapterFactory.create())
        }.createService()

Download

  • Add the following to your project level build.gradle:
allprojects {
 repositories {
  maven { url "https://jitpack.io" }
 }
}
  • Add this to your app build.gradle:
dependencies {
 implementation 'com.github.amalhanaja:retrofit2-kotlin:1.0.0'
}

License

Copyright 2018 Alfian Akmal Hanantio

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Special thanks to square, JetBrains and jitpack.io for their contributions to this project.