Created
September 15, 2019 21:04
-
-
Save dubeboy/f391d67e6390cbd4a3730e3ce811e662 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package za.co.dubedivine.groceryapp.data.remote | |
import retrofit2.Retrofit | |
import retrofit2.converter.gson.GsonConverterFactory | |
import okhttp3.OkHttpClient | |
import okhttp3.logging.HttpLoggingInterceptor | |
object GroceryServiceFactory { | |
private const val API_BASE_URL = "http://<YOUR_IP_ADRESS_HERE>:8080/" | |
// add the logging interceptor | |
fun makeService(): GroceryService { | |
val logging = HttpLoggingInterceptor() | |
logging.apply { logging.level = HttpLoggingInterceptor.Level.BODY } | |
val httpClient = OkHttpClient.Builder().addInterceptor(logging) | |
val builder = Retrofit.Builder() | |
.baseUrl(API_BASE_URL) | |
.addConverterFactory(GsonConverterFactory.create()) | |
return builder | |
.client(httpClient.build()) | |
.build().create(GroceryService::class.java) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment