안드로이드/Retrofit
안드로이드 Retrofit Intercepter 적용
김어찐
2022. 11. 28. 16:17
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