I'm totally new in KotlinJs and I wanted to check its potential in server-less service development.
I decided to start with calling external API with HTTP GET method using XMLHttpRequest() suggested in KotlinJs documentation. However, I cannot come up with any way of using it without dynamic mechanism.
fun main(args: Array<String>) {
val url = "https://jsonplaceholder.typicode.com/todos/1"
var xhttp: dynamic = XMLHttpRequest()
xhttp.open("GET", url, true)
xhttp.onreadystatechange = fun() {
if (xhttp.readyState == 4) {
println(xhttp.responseJson)
}
}
xhttp.send()
}
Of course this example works perfectly fine, but I feel like it has to be better way of doing it without disabling Kotlin's type checker.
- Is there any way of doing it using KotlinJs only (without dynamic) ?
- If it is not possible, could someone at least explain why?