Keep the API style consensus for request model in httpx #2717
-
|
We now have a different API style, like the following code, between the non-stream and stream requests. resp = httpx.get("http://demo")
resp.raise_for_status()
with httpx.stream("http://demo") as resp:
resp.raise_for_status()I prefer we keep the consensus API style as the developer does in the requests lib. with requests.get("http://demo") as resp:
resp.raise_for_status()
with requests.get("http://demo", stream=True) as resp:
resp.raise_for_status()We can reach this target by two different ways:
I think there would be two benefits we can get from this feature:
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
This seems to be the intended design. But I do agree with your idea, because I think stream=True is essentially just a parameter of the request, while the method of the request is the essence. On the other hand, the inconsistency of the API does make it difficult to migrate from the requests library. At the same time, having both client.stream and client.xxx(stream=True) APIs should not cause backward incompatibility. |
Beta Was this translation helpful? Give feedback.
It's absolutely a deliberate design decision.
Having a
stream=Trueparameter is a code-smell, and lets you do two different kinds of broken things......or this case, which is worse...
We've deliberately opted for a more constrained style here that is always explicit about when a streaming response is opened and closed.