ktmx-ktor

Provides route handler and HTML DSL extension for working with ktor and kotlinx.html.

Partial HTML responses

respondHtmlPartial enables partial HTML responses.

routing {
get("/ktmx") {
call.respondPartialHtml {
// no html {} needed
span {
+"Success!"
}
}
}
}

Type-safe routing

hxGet and the likes provide interop with Ktor's type-safe routing.

// Setup type-safe routing
@Resource("/hello")
class Hello(val name: String)

fun Application.configureRouting() {
// Keep a reference to the ResourcesFormat handy (recommended)
val rf = install(Resources).resourcesFormat

routing {
get("/recommended") {
call.respondPartialHtml {
button {
hxPost(rf, Hello("World"))
+"Click Me!"
}
}
}
get("/alternative") {
call.respondPartialHtml {
button {
// You can also get it from anywhere
hxPost(application.plugin(Resources).resourcesFormat, Hello("World"))
+"Click Me!"
}
}
}
}
}

Provides route handler and HTML DSL extension for working with ktor and kotlinx.html.

Partial HTML responses

respondHtmlPartial enables partial HTML responses.

routing {
get("/ktmx") {
call.respondPartialHtml {
// no html {} needed
span {
+"Success!"
}
}
}
}

Type-safe routing

hxGet and the likes provide interop with Ktor's type-safe routing.

// Setup type-safe routing
@Resource("/hello")
class Hello(val name: String)

fun Application.configureRouting() {
// Keep a reference to the ResourcesFormat handy (recommended)
val rf = install(Resources).resourcesFormat

routing {
get("/recommended") {
call.respondPartialHtml {
button {
hxPost(rf, Hello("World"))
+"Click Me!"
}
}
}
get("/alternative") {
call.respondPartialHtml {
button {
// You can also get it from anywhere
hxPost(application.plugin(Resources).resourcesFormat, Hello("World"))
+"Click Me!"
}
}
}
}
}

Packages

Link copied to clipboard
common