728x90
import com.google.gson.GsonBuilder
import okhttp3.OkHttpClient
import okhttp3.logging.HttpLoggingInterceptor
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory
class RetrofitInstance {
companion object {
val BASE_URL: String = "https://jsonplaceholder.typicode.com"
val interceptor = HttpLoggingInterceptor().apply {
this.level = HttpLoggingInterceptor.Level.BODY
}
val client = OkHttpClient.Builder().apply {
this.addInterceptor(interceptor)
}.build()
fun getRetrofitInstance(): Retrofit {
return Retrofit.Builder()
.baseUrl(BASE_URL)
.client(client)
.addConverterFactory(GsonConverterFactory.create(GsonBuilder().create()))
.build()
}
}
}
728x90
'안드로이드 > Retrofit' 카테고리의 다른 글
안드로이드 Retrofit TimeOut (0) | 2022.11.28 |
---|---|
안드로이드 retrofit builder (0) | 2022.11.27 |
안드로이드 Retrofit MultipartFormdata (0) | 2022.08.10 |