apigen-ts
apigen-ts copied to clipboard
[feat] Support application/event-stream
Now the SSE endpoints are treated as a short-lived request. Ideally such api should return an async iterator
For the record: https://www.npmjs.com/package/fetch-event-stream may be helpful
Hi, @onichandame. Yes, the SSE endpoints is not supported in apigen-ts. I checked my projects and usually I use reconnecting-eventsource package for SSE.
I can add this feature to apigen-ts, but I'm not sure how to identify that the endpoint is SSE from the OpenAPI spec?
@vladkens when the response content type is text/event-stream
Hi, @onichandame. I have looked into the question. Initially, the correct solution seems to be to use EventSource, as it is the browser's native way of handling SSE. But it has problems with not being able to pass headers - which are used by some services for authorization, etc.
The library you gave as an example solves this problem. But, it do do manual HTTP parsing, which seems a bit more extensive and complicated than the basic functionality of the library.
At this stage, if you don't have many methods, you can override specific method using extends, for example.
@vladkens thank you! extending the ApiClient is exactly what I have been doing now. the DX is ok as SSE endpoints don't change often