https://kotlinlang.org logo
Title
m

Marcel Champagne

08/22/2020, 1:32 AM
Hi all, I'm trying out Ktor for the first time and immediately running into issues. I'm just trying to follow the basis HTTP client setup. I used the Kotlin Intellij Plugin and everything builds fine but the second I try to make a get request I'm getting an error. The following code doesn't compile with line 16, but does without:
14 fun Application.module(testing: Boolean = false) {
15    val client = HttpClient(CIO)
16    val htmlContent = client.get<String>("<https://en.wikipedia.org/wiki/Main_Page>")
17 }
But I the the following error
Error:(16, 30) Kotlin: Unresolved reference. None of the following candidates is applicable because of receiver type mismatch:
public inline operator fun <K, V> Map<out String, [ERROR : Explicit type argument expected for V]>.get(key: String): [ERROR : Explicit type argument expected for V]? defined in kotlin.collections
public operator fun MatchGroupCollection.get(name: String): MatchGroup? defined in kotlin.text
m

Marc Knaup

08/22/2020, 1:22 PM
Kotlin’s error messages are quite confusing when it comes to extension functions. You have to import the
get
method first:
import io.ktor.client.request.*
And your function must be a `suspend fun`:
suspend fun Application.module(testing: Boolean = false) {
#ktor is better suited for getting Ktor-related help 😉