Kickstart Kotlin Web Assembly with Spring Boot

Submitted by Dickens A S on Sun, 11/03/2019 - 13:22

Easily create Kotlin Web Assembly project from these multiplatform boilerplate Gradle DSL

Kotlin Code

package wasm

fun main() {
    println("Hello World!")

JavaScript Code

No need to write JavaScript code simply put this HTML

<script src="build/bin/wasm/releaseExecutable/sboot_wasm.wasm.js" wasm="build/bin/wasm/releaseExecutable/sboot_wasm.wasm"> </script>

Run gradle command

  gradle assemble

Run gradle command

  gradle run

Browse http://localhost:8080/index.html

Check your browser console for text output "Hello World!" which will be the output from Web Assembly Code

Spring Boot is used as a server to give MIME content-type as "application/wasm" , currently browsers does not recognize .wasm files with that MIME

Spring boot is also written in Kotlin, the gradle is also written in Kotlin

Source Code

End Of Article

Add new comment