Philipp Mayer
08/20/2023, 6:20 PMdave
08/20/2023, 6:25 PMMikael Ståldal
08/27/2023, 7:41 AMhtmxWebjar()
is only useful if HTML is the only webjar you use, right? If you also use others (e.g. Hyperscript), then you have to use the old webJars()
.dave
08/27/2023, 8:39 AMval app = routes(
htmxWebjars(),
"/" bind GET to routes(
// Respond to htmx powered requests
Request.isHtmx bind { Response(OK).with(view of Time(Date())) },
// Standard requests get routed to here
orElse bind { Response(OK).with(view of Index) }
)
)
Mikael Ståldal
08/27/2023, 9:11 AMMikael Ståldal
08/27/2023, 9:34 AMRequest.isHtmx
is useful, using it in my example project now: https://github.com/mikaelstaldal/htmx-http4k-dsldave
08/27/2023, 9:38 AMMikael Ståldal
08/27/2023, 3:37 PMhttp4k-core
(besides the webJars
function):
import org.http4k.routing.ResourceLoader
import org.http4k.routing.static
fun webjar(name: String, version: String) =
static(ResourceLoader.Classpath("/META-INF/resources/webjars/$name/$version/dist"))
Then you can use it like this:
htmxWebjars(),
webjar("bootstrap", "5.3.0")
given these dependencies:
<dependency>
<groupId>org.http4k</groupId>
<artifactId>http4k-core</artifactId>
</dependency>
<dependency>
<groupId>org.http4k</groupId>
<artifactId>http4k-htmx</artifactId>
</dependency>
<dependency>
<groupId>org.webjars.npm</groupId>
<artifactId>bootstrap</artifactId>
<version>5.3.0</version>
</dependency>
dave
08/27/2023, 3:43 PM