Elena van Engelen
03/29/2023, 9:53 AMval response = <http://httpClient.post|httpClient.post><MyClass1> {
url("$myUrl")
contentType(ContentType.Application.Json)
body = MyClass2(MyClass3(param1, param2))
}
Aleksei Tirman [JB]
03/29/2023, 10:28 AMElena van Engelen
03/29/2023, 10:54 AMimport io.ktor.client.*
import io.ktor.client.request.*
import io.ktor.client.statement.*
import io.ktor.http.*
import mu.KotlinLogging
import nl.edsn.generated.mar.models.*
import org.springframework.http.*
import org.springframework.stereotype.Service
@Service
class ExampleService(private val httpClient: HttpClient) {
fun example(){
val url = "bla"
val response = <http://httpClient.post|httpClient.post><String> {
url(url)
contentType(MediaType.APPLICATION_JSON)
body("")
}
}
companion object {
val log = KotlinLogging.logger {}
}
}
Somehow I cannot get the DSL to compile after post.IntelliJ does not suggest any useful imports , chatGPT was also useless in this case. Its probably something in imports? I have these dependancies:
implementation("io.ktor:ktor-client-core:$ktorVersion")
implementation("io.ktor:ktor-client-okhttp:$ktorVersion")
implementation("io.ktor:ktor-client-logging:$ktorVersion")
Aleksei Tirman [JB]
03/29/2023, 3:04 PMAleksei Tirman [JB]
03/29/2023, 3:06 PM2.*
, then you need to remove the String
type parameter and call the body
method. Please have a look at the migration guide.Elena van Engelen
03/30/2023, 6:39 AM