Was trying to get `fetch` working and this is as f...
# webassembly
j
Was trying to get
fetch
working and this is as far as I can get using the experimental coroutines wasm:
Copy code
val resp = Promise.resolve(window.fetch("/customers".asDynamic()).asDynamic()).await<org.w3c.fetch.Response>()
val json = Promise.resolve(resp.json().asDynamic()).await<Dynamic>()
println(json)
Can't figure out how to get the json into an
Array<Something>
- any ideas?
s
Not yet supported, but you can workaround via a manual wrapper like https://github.com/kowasm/kowasm/blob/main/kotlinx-nodejs-wasm/src/wasmMain/kotlin/org/nodejs/ExternalWrapper.kt. There is an ongoing refactoring to improve how dynamic types are translated in Kotlin/Wasm, and also ongoing refinement on Promise to Coroutines mechanics, so fetch should be easier to leverage a bit later.
j
Thanks! I got it working: https://github.com/jamesward/nks/blob/wasm/bootiful/wasmweb/src/wasmMain/kotlin/Main.kt Not elegant yet, but understand improvements are still in the works.