web

This module allows to create a web server and defines HTTP routes using a proper DSL.

fun main() {
val userService = ...
webServer {
router {
GET("/") {
val content = content(userService.findAll())
ok().contentType(MediaType.TEXT_HTML).body(content)
}
(GET("/api") and accept(MediaType.APPLICATION_JSON)) {
ok().contentType(MediaType.APPLICATION_JSON).body(userService.findAll())
}
}
}.startNodejs() // could be startServer() when WASI runtimes will support WasmGC
}

fun content(users: List<User>) = createHtml {
head {
metaCharsetUtf8()
}
body {
h1 { +"Users" }
ul {
users.forEach { user ->
li { +user.name }
}
}
}
}

This module allows to create a web server and defines HTTP routes using a proper DSL.

fun main() {
val userService = ...
webServer {
router {
GET("/") {
val content = content(userService.findAll())
ok().contentType(MediaType.TEXT_HTML).body(content)
}
(GET("/api") and accept(MediaType.APPLICATION_JSON)) {
ok().contentType(MediaType.APPLICATION_JSON).body(userService.findAll())
}
}
}.startNodejs() // could be startServer() when WASI runtimes will support WasmGC
}

fun content(users: List<User>) = createHtml {
head {
metaCharsetUtf8()
}
body {
h1 { +"Users" }
ul {
users.forEach { user ->
li { +user.name }
}
}
}
}

Packages

Link copied to clipboard
common

Package for web related stuff.

Link copied to clipboard
common

Package for HTTP related stuff.

Link copied to clipboard
common

Package for HTTP server related stuff.

Link copied to clipboard

Package for Nodejs support.