A Swift package for Server-Sent Events (SSE) with dual mode support: server side streaming for Vapor and client-side consumption for iOS/macOS/Linux.
- Shared types across server and client
- Native async/await API using Swift Concurrency
- Full SSE specification compliance
- Automatic reconnection with configurable strategies
- Linux compatible for Vapor deployments
dependencies: [
.package(url: "https://github.com/squidypal/SwiftSSE.git", from: "1.0.0")
]import SwiftSSEServer
app.get("events") { req -> EventStream in
EventStream { writer in
for i in 1...10 {
try await writer.send(SSEEvent(data: "Event \(i)"))
try await Task.sleep(for: .seconds(1))
}
}
}import SwiftSSEClient
let client = SSEClient(url: URL(string: "https://api.example.com/events")!)
for try await event in client.events {
print(event.data)
}| Module | Purpose |
|---|---|
| SwiftSSECore | Shared types and event parsing |
| SwiftSSEServer | Vapor middleware & response streaming |
| SwiftSSEClient | URLSession (Apple) / AsyncHTTPClient (Linux) consumer |
- SwiftSSECore: Linux, macOS, iOS
- SwiftSSEServer: Linux, macOS
- SwiftSSEClient: Linux, macOS, iOS
- Swift 6.0+
- macOS 12+ / iOS 15+
- Vapor 4+ (server module)
MIT