Skip to content

Instantly share code, notes, and snippets.

@pavlospt
Last active March 24, 2020 11:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pavlospt/59282a2036252c280932c9419ce39f2a to your computer and use it in GitHub Desktop.
Save pavlospt/59282a2036252c280932c9419ce39f2a to your computer and use it in GitHub Desktop.
private val client = HttpClient(OkHttp) {
install(JsonFeature) {
serializer = GsonSerializer()
}
install(HttpTimeout) {
requestTimeoutMillis = 30_000
}
install(Logging) {
logger = Logger.DEFAULT
level = LogLevel.ALL
}
engine {
config {
followRedirects(true)
followSslRedirects(true)
connectTimeout(30, TimeUnit.SECONDS)
readTimeout(30, TimeUnit.SECONDS)
writeTimeout(30, TimeUnit.SECONDS)
}
}
}
fun Application.module(testing: Boolean = false) {
routing {
post("/a/route") {
call.respond(HttpStatusCodes.OK)
val urlResponse = withContext(Dispatchers.IO) {
client.post("url") { body = someBodyHere }
}
val urlResponse2 = withContext(Dispatchers.IO) {
client.post("url2") { body = urlResponse.something.from.first.call }
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment