apigen-ts icon indicating copy to clipboard operation
apigen-ts copied to clipboard

[feat] Support application/event-stream

Open onichandame opened this issue 11 months ago • 5 comments

Now the SSE endpoints are treated as a short-lived request. Ideally such api should return an async iterator

onichandame avatar Dec 31 '24 06:12 onichandame

For the record: https://www.npmjs.com/package/fetch-event-stream may be helpful

onichandame avatar Dec 31 '24 06:12 onichandame

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 avatar Jan 11 '25 05:01 vladkens

@vladkens when the response content type is text/event-stream image

onichandame avatar Jan 13 '25 03:01 onichandame

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 avatar Jan 19 '25 05:01 vladkens

@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

onichandame avatar Jan 20 '25 04:01 onichandame