httpx
httpx copied to clipboard
Support Server-sent Events
close #1278
Thanks @abersheeran...
Some thoughts:
- I've got mixed feelings about if we should be supporting this, or if we should just close off https://github.com/encode/httpx/issues/1278, as per this comment (For example... are folks actually using/wanting this, or are we just adding functionality for the sake of it?)
- If we do support it, should the return result be a dict or an object with attributes?
- I think the documentation for this should probably be in the "Advanced" section, rather than the quickstart.
Server-sent events is a stable, simple specification whose behavior won't change for the foreseeable future, and I don't think it's too difficult to maintain directly within httpx.
I think the documentation for this should probably be in the "Advanced" section, rather than the quickstart.
OK, I'll revise this part of the documentation after we've settled on a final conclusion.
Don't get me wrong, I love SSE. I feel that in many situations when someone wants to reach for websockets, they can get by with a lighter-weight SSE implementation. With my :heart: for SSE established, and with the express intent to speak only for myself, here are my thoughts.
are folks actually using/wanting this, or are we just adding functionality for the sake of it?
This seems out of scope to me. If I want this support, I want to build it myself or use another lib on top of httpx. It is a protocol layer that lives above HTTP. I want my HTTP client to focus on HTTP not on handling message parsing for a protocol that is not within its core functionality. By the same logic, I would not want httpx to become a GraphQL client either. These are functions that live above and should implement httpx and not be a part of it.
If we do support it, should the return result be a dict or an object with attributes?
Typed objects. They will be easier to use, and the protocol is simple enough that there are only a handful of models needed with fairly basic properties.
I think the documentation for this should probably be in the "Advanced" section, rather than the quickstart.
Agreed
If you need use cases a large part of my last web application is untested since we are widely using SSE ;) BTW while trying to implement the proposed external solution I got stuck with this problem: using EventSourceResponse from see-starlette when I try to to res = await client.stream("GET", url) the call hangs. I didn't figure why yet but without a response it's impossible to proceed with an external solution.
@abersheeran would you allow me to make a package out of your code?
@abersheeran would you allow me to make a package out of your code?
Ok.