Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/alephao/swift-http-types-htmx
swift-http-types extensions for htmx
https://github.com/alephao/swift-http-types-htmx
htmx server swift swift-http-types
Last synced: 25 days ago
JSON representation
swift-http-types extensions for htmx
- Host: GitHub
- URL: https://github.com/alephao/swift-http-types-htmx
- Owner: alephao
- License: mit
- Created: 2024-09-14T12:49:23.000Z (about 2 months ago)
- Default Branch: main
- Last Pushed: 2024-09-18T23:03:59.000Z (about 2 months ago)
- Last Synced: 2024-09-29T11:25:37.996Z (about 1 month ago)
- Topics: htmx, server, swift, swift-http-types
- Language: Swift
- Homepage:
- Size: 406 KB
- Stars: 16
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-htmx - swift-http-types-htmx - HTMX extensions for swift-http-types (Tools)
README
# swift-http-types-htmx
[![CI](https://github.com/alephao/swift-http-types-htmx/actions/workflows/ci.yml/badge.svg)](https://github.com/alephao/swift-http-types-htmx/actions/workflows/ci.yml)
[![codecov](https://codecov.io/gh/alephao/swift-http-types-htmx/graph/badge.svg?token=Ef5FszDA3Y)](https://codecov.io/gh/alephao/swift-http-types-htmx)
[![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2Falephao%2Fswift-http-types-htmx%2Fbadge%3Ftype%3Dswift-versions)](https://swiftpackageindex.com/alephao/swift-http-types-htmx)
[![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2Falephao%2Fswift-http-types-htmx%2Fbadge%3Ftype%3Dplatforms)](https://swiftpackageindex.com/alephao/swift-http-types-htmx)[HTMX](https://htmx.org) extensions for [`apple/swift-http-types`](https://github.com/apple/swift-http-types).
The package provides extensions for:
- `HTTPField.Name` initializers, e.g.: `HTTPField.Name.hxLocation` = `'HX-Location'`
- `HTTPField` initializers e.g.: `HTTPField.hxLocation('/path')` = `HX-Location: /path`
- `HTTPFields` getters e.g.: `HTTPFields.hxRequest: Bool`, `HTTPFields.hxLocation: String?`It also provides HTMX documentation in-code:
![](/Resources/ss-xcode-doc.png)
### Usage
```swift
import HTTPTypes
import HTTPTypesHtmx// Creating HTTPFields
let headersViaArray = HTTPFields([
.hxRetarget("#myDiv"),
.hxReswap(.outerHTML),
])let headersViaDictionary: HTTPFields = [
.hxRetarget: "#myDiv",
.hxReswap: HxSwap.outerHTML,
]// Getting values from HTTPFields
let exampleRequestHeaders = HTTPFields([
.hxBoosted(),
.hxRequest(),
.hxTarget(id: "myDiv")
])requestHeaders.hxBoosted // true
requestHeaders.hxRequest // true
requestHeaders.hxTarget // "myDiv"
```## Examples
There is an [example project](Examples) of a server using the [Hummingbird Framework](http://github.com/hummingbird-project/hummingbird) with a few exampels on how to use HTMX response headers to drive the application.
There are also tests for all handlers, demonstrating how this library can be used to mock HTMX requests for testing purposes.
## Installation
Add the dependency to Package.swift
```swift
dependencies: [
.package(url: "https://github.com/alephao/swift-http-types-htmx.git", from: "0.3.0")
],
```Add the products you want to use to the target dependencies
```swift
.target(
name: "MyTarget",
dependencies: [
.product(name: "HTTPTypesHtmx", package: "swift-htmx"),
]
)
```