Last active
August 12, 2021 07:55
-
-
Save axiel7/ababf580b0b6a48df6d114fb0ef17de7 to your computer and use it in GitHub Desktop.
Ktor HttpClient for Android
This file contains 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
import android.util.Log | |
import io.ktor.client.* | |
import io.ktor.client.engine.okhttp.* | |
import io.ktor.client.features.logging.* | |
import java.util.concurrent.TimeUnit | |
object KtorClient { | |
private const val TIME_OUT = 60_000L | |
val ktorHttpClient = HttpClient(OkHttp) { | |
//evitar excepcion al recibir error del servidor | |
expectSuccess = false | |
engine { | |
config { | |
connectTimeout(TIME_OUT, TimeUnit.MILLISECONDS) | |
callTimeout(TIME_OUT, TimeUnit.MILLISECONDS) | |
readTimeout(TIME_OUT, TimeUnit.MILLISECONDS) | |
writeTimeout(TIME_OUT, TimeUnit.MILLISECONDS) | |
retryOnConnectionFailure(true) | |
} | |
} | |
//TODO: desactivar en produccion | |
install(Logging) { | |
logger = object : Logger { | |
override fun log(message: String) { | |
Log.v("Ktor =>", message) | |
} | |
} | |
level = LogLevel.ALL | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment