1class RetrofitService {
2
3 private val BASE_URL = "https://jsonplaceholder.typicode.com/"
4
5
6 private val loggingInterceptor = HttpLoggingInterceptor()
7
8
9 private val httpClient = OkHttpClient.Builder().addInterceptor(loggingInterceptor).build()
10
11 private val builder = Retrofit.Builder()
12 .baseUrl(BASE_URL)
13 .addConverterFactory(GsonConverterFactory.create())
14 .client(httpClient)
15
16 private val retrofit = builder.build()
17
18 init {
19 loggingInterceptor.level = HttpLoggingInterceptor.Level.BODY
20 }
21
22 fun <S> createService(
23 serviceClass: Class<S>
24 ): S {
25 return retrofit.create(serviceClass)
26 }
27}
1android {
2 compileOptions {
3 targetCompatibility = "8"
4 sourceCompatibility = "8"
5 }
6}