Support for SSE (EventSource)
koraykoska opened this issue · 3 comments
koraykoska commented
I didn't find anything so thought I should ask. Is there any support for EventSource (client side of course)? If not, would it be possible to build something around the existing library without having to support it upstream?
czechboy0 commented
Hi @koraykoska,
you can build both a client and a server side of SSE using Swift OpenAPI Generator, which can use AHC under the hood.
Steps:
- Clone this example project: https://github.com/apple/swift-openapi-generator/tree/main/Examples/event-streams-client-example
- Switch the transport from the URLSession transport to the AsyncHTTPClient transport: https://github.com/swift-server/swift-openapi-async-http-client
- Update the OpenAPI doc to match the service you're connecting to
czechboy0 commented
More docs on using SSE and other event streams: https://swiftpackageindex.com/apple/swift-openapi-generator/1.2.0/documentation/swift-openapi-generator/useful-openapi-patterns#Event-streams-JSON-Lines-JSON-Sequence-and-Server-sent-Events
koraykoska commented
Thank you @czechboy0 ! Just what I was looking for.