vapor/vapor

SSE Client Consumption in Vapor

curiouscoders5 opened this issue · 1 comments

Is your feature request related to a problem? Please describe.

Looking for SSE client side support. Namely, being able to consume an external resource which is using Server-Sent Events (link to spec).

Here's an example external resource which can be consumed via SSE:
https://platform.openai.com/docs/api-reference/making-requests
curl https://api.openai.com/v1/completions
-H "Content-Type: application/json"
-H "Authorization: Bearer YOUR_API_KEY"
-d '{"model": "text-davinci-003", "prompt": "Write the code for how to do SSE in swift", "temperature": 0, "max_tokens": 400, "stream": true}'

For testing purposes, it would be ideal if this implementation also included Server side support for SSE, namely so you could output events via SSE.

Here's links to libraries that may be useful for implementing:

https://github.com/swift-server/async-http-client#streaming
https://github.com/inaka/EventSource/blob/master/EventSource/EventSource.swift
https://github.com/inaka/EventSource/blob/master/EventSource/EventStreamParser.swift

Describe the solution you'd like
A Vapor package that can be used to consume SSE events (aka client-side) from an external API.

@Joannis tagging you here for visibility.

Thanks absolute boatloads for taking a look at this.