https://kotlinlang.org logo
#ktor
Title
# ktor
v

Vinicius Carvalho

01/27/2019, 8:59 PM
Copy code
suspend fun request(offset: Int, limit: Int, endpoint: String) : ApiResponse<List<Map<String,Any>>> {
        val end = limit + offset
        
        return retroClient.request(endpoint = endpoint, offset = offset, limit = limit).execute().body()!! //using retrofit, works

//        internalClient.request {
//            url(URL("$BASE_URL$endpoint?offset=$offset&limit=$limit&format=json&api_key=$API_KEY"))
//            method = HttpMethod.Get
//            headers {
//                append("User-Agent" , "Ktor Apache Client")
//                append("Content-Type", "application/json")
//            }
//        }
    }
u

uli

01/28/2019, 3:17 AM
First of all you might want to use launch instead of async if you do not await a result
v

Vinicius Carvalho

01/28/2019, 3:28 AM
I tried that too, ain't the source of problems
initially I was waiting for results
but it doesn't matter which one you use, so that ain't the cause
e

e5l

01/28/2019, 8:12 AM
Hi @Vinicius Carvalho, what engine do you use?
v

Vinicius Carvalho

01/28/2019, 1:39 PM
@e5l Apache
Copy code
val internalClient = HttpClient(Apache) {
        engine {
            connectTimeout = 30_000
            socketTimeout = 60_000
        }
        install(JsonFeature){
            serializer = JacksonSerializer{
                jacksonObjectMapper()
                    .registerModule(JavaTimeModule())
                    .configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
            }

        }
    }
e

e5l

01/28/2019, 2:16 PM
Could you try it with
1.1.2
? We fixed some
Apache
performance problems.
v

Vinicius Carvalho

01/28/2019, 3:27 PM
absolutely, thank you
6 Views