Skip to content

Instantly share code, notes, and snippets.

@hissain
Last active April 1, 2020 22:47
Show Gist options
  • Save hissain/35513214fa7eac6ec9ecf0808bb2573e to your computer and use it in GitHub Desktop.
Save hissain/35513214fa7eac6ec9ecf0808bb2573e to your computer and use it in GitHub Desktop.
Service Builder Class
import okhttp3.OkHttpClient
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory
object ServiceBuilder {
private val client = OkHttpClient.Builder().build()
private val retrofit = Retrofit.Builder()
.baseUrl("http://api.server.com") // change this IP for testing by your actual machine IP
.addConverterFactory(GsonConverterFactory.create())
.client(client)
.build()
fun<T> buildService(service: Class<T>): T{
return retrofit.create(service)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment