https://github.com/iodesystems/kotlinx-htmx
Htmx plugin for kotlinx-html
https://github.com/iodesystems/kotlinx-htmx
Last synced: about 1 year ago
JSON representation
Htmx plugin for kotlinx-html
- Host: GitHub
- URL: https://github.com/iodesystems/kotlinx-htmx
- Owner: IodeSystems
- Created: 2023-12-24T02:23:52.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2025-06-12T13:37:25.000Z (about 1 year ago)
- Last Synced: 2025-06-12T14:44:00.855Z (about 1 year ago)
- Language: Kotlin
- Size: 147 KB
- Stars: 20
- Watchers: 1
- Forks: 1
- Open Issues: 9
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# kotlinx-htmx
Ever wanted to... build (?) your no-build web application in kotlin?
`kotlinx-htmx` supports 100% of the apis from [htmx.org](https://htmx.org/) on top of `kotlinx.html`.
## TL;DR
```kotlin
data class Counter(val count: Int)
@PostMapping("/counter")
fun counterButton(
@RequestBody counter: Counter = Counter(0)
) = Htmx {
if (counter.count > 0) {
// Let the indicator show!
Thread.sleep(1.seconds.toJavaDuration())
}
div{
id = "counter"
div{
id = "indicator"
+"Loading..."
}
button {
hx {
post("/counter")
swap()
indicator("#indicator")
trigger {
click()
queue(HtmxTrigger.Queue.first)
vals(objectMapper.writeValueAsString(counter.copy(count = counter.count + 1)))
}
}
+"Click Count ${counter.count}"
}
}
}
```
See the `example` project for more details.
## Installation
Maven:
```xml
...
com.iodesystems.kotlinx-htmx
htmx
${check-mvn-repository}
com.iodesystems.kotlinx-htmx
spring
${check-mvn-repository}
...
```
Gradle:
```kotlin
// file: build.gradle.kts
repositories {
mavenCentral()
}
dependencies {
implementation("com.iodesystems.kotlinx-htmx:htmx:${check-mvn-repository}")
// If you want to use it with spring-web
implementation("com.iodesystems.kotlinx-htmx:spring:${check-mvn-repository}")
}
```
## Spring Integration
To be able to return `Htmx` from your controller, you need to add `HtmxHttpMessageConverter` to your `WebMvcConfigurer`:
```kotlin
@Configuration
open class WebConfig : WebMvcConfigurer {
override fun extendMessageConverters(converters: MutableList>) {
converters.add(0, HtmxHttpMessageConverter())
}
}
```
# License
MIT License