Hi I am new to ktor , moving from reactive WebClient and having a stupid issue with non compiling code in ktor, does someone have a good example in GitHub for a post Kotlin/JVM + Spring boot 3, e.g.
Copy code
val response = <http://httpClient.post|httpClient.post><MyClass1> {
url("$myUrl")
contentType(ContentType.Application.Json)
body = MyClass2(MyClass3(param1, param2))
}
a
Aleksei Tirman [JB]
03/29/2023, 10:28 AM
Can you share a complete code snippet?
e
Elena van Engelen
03/29/2023, 10:54 AM
Copy code
import 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: