An open API service indexing awesome lists of open source software.

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

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