-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApiFactory.kt
More file actions
37 lines (30 loc) · 1.04 KB
/
ApiFactory.kt
File metadata and controls
37 lines (30 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package com.sopt.dive.data
import com.jakewharton.retrofit2.converter.kotlinx.serialization.asConverterFactory
import com.sopt.dive.BuildConfig
import kotlinx.serialization.json.Json
import okhttp3.MediaType.Companion.toMediaType
import okhttp3.OkHttpClient
import okhttp3.logging.HttpLoggingInterceptor
import retrofit2.Retrofit
object ApiFactory {
private val BASE_URL: String = BuildConfig.BASE_URL
private val loggingInterceptor = HttpLoggingInterceptor().apply {
level = HttpLoggingInterceptor.Level.BODY
}
private val client = OkHttpClient.Builder()
.addInterceptor(loggingInterceptor)
.build()
private val json = Json {
explicitNulls = false
}
val retrofit: Retrofit by lazy {
Retrofit.Builder()
.baseUrl(BASE_URL)
.client(client)
.addConverterFactory(
json.asConverterFactory("application/json".toMediaType())
)
.build()
}
inline fun <reified T> create(): T = retrofit.create(T::class.java)
}