Typed htmx values for swift on server
- Htmx: Type-safe HTMX attribute names
- HTTPTypesHtmx: support for apple/swift-http-types
- HtmlHtmx: support for pointfreeco/swift-html
If you're using pointfreeco/swift-html, HtmlHtmx will add htmx extentions to Attributes.
import Htmx
import HtmlHtmx
func example() -> Node {
.div(
.button(
attributes: [
.hxGet("/my-endpoint"),
.hxTarget("#myDiv"),
.hxSwap(.outerHTML),
],
.text("Swapping html via hx-swap and hx-target")
),
.div(attributes: [.id("myDiv")], .text("I'm getting replaced"))
)
}
HTTPTypesHtmx
adds extensions to swift-http-types
's types HTTPField
and HTTPField.Name
import Htmx
import HTTPTypesHtmx
let headers = HTTPFields([
.hxRetarget("#myDiv"),
.hxReswap(.outerHTML),
])
Check the example project here
Add the dependency to Package.swift
dependencies: [
.package(url: "https://github.com/alephao/swift-htmx.git", from: "0.3.0")
],
Add the products you want to use to the target dependencies
.target(
name: "MyTarget",
dependencies: [
.product(name: "Htmx", package: "swift-htmx"),
.product(name: "HTTPTypesHtmx", package: "swift-htmx"),
.product(name: "HtmlHtmx", package: "swift-htmx"),
]
)