Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feat] Support application/event-stream #4

Open
onichandame opened this issue Dec 31, 2024 · 5 comments
Open

[feat] Support application/event-stream #4

onichandame opened this issue Dec 31, 2024 · 5 comments

Comments

@onichandame
Copy link

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

@onichandame
Copy link
Author

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

@vladkens
Copy link
Owner

vladkens commented Jan 11, 2025

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?

@onichandame
Copy link
Author

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

@vladkens
Copy link
Owner

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.

@onichandame
Copy link
Author

@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants