-
-
Notifications
You must be signed in to change notification settings - Fork 813
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
Same interface for for all http methods in api.py #395
Comments
Thanks for opening this issue, definitely an oversight! We should fix the discrepancies and write a unit test using Do you think you could tackle this issue? |
I would counter that this is not particularly an oversight, but a deliberate choice based on the capabilities of HTTP, and also matching the Though the underlying I would recommend referring to httpx.request for similar uses, that go outside the standard expectations for HTTP methods. |
Actually, as the OP pointed out, httpx's behavior does not match the requests API. The requests API uses That being said, I actually agree with you that those functions should, in fact, not have params for things they don't actually support. And I agree with your suggestion of using |
@StephenBrown2 @thebigmunch You've both got good points, keeping our API trimmed in areas where parameters typically aren't found or have no meaning is a good way to steer our users to doing the right thing. It looks like the I'd also like to mention that I'm still interested in a unit test that can track the API conformance of each method, especially for comparing across |
Thanks for your comments! I understand that having a more restrictive interface enforces better practices but I think that should be done in there server-side rather than enforcing it in client-side. As it excludes some using the convenient function for some servers, such as Elasticsearch. But if we do enforce the strict arguments we should add it to th compatibility docs https://github.com/encode/httpx/blob/master/docs/compatibility.md Relevant excerpts I found:
RFC about GET and request message.
Would love to hear your feedback and final decision! @StephenBrown2 @thebigmunch @sethmlarson |
I think that's reason enough not to directly support that in the specific methods. |
Indeed - this is deliberate. Our lower-level APIs (eg. build up a request instance explicitly, and then send it) might conceivably be a good point at which to allow users to do broken things, but our top level API doesn't need to. |
For your case @jtmiclat you can use the Client.request() interface and set the method to "GET". If we're intending to not have body parameters available on methods that don't have bodies typically we should remove from .delete() |
I'd potentially be okay with us removing it from |
Relevant excerpt from RFC 7231 Section 4.3.5:
which as far as I can tell is the same as
|
Also, as I said here, OpenAPI forbids a body for GET, DELETE, and HEAD. |
Ah, double checked HTTPbis, which supersedes the original RFC in a few places. And yes, we should drop em on .delete too. (Divergence from requests, but I’m totally okay with it) https://tools.ietf.org/html/draft-ietf-httpbis-semantics-05#section-7.3.5 |
When using elasticsearch with
httpx
, I quickly realized thathttpx.get
does not take injson
as a function argument. A quick look atapi.py
showed that not all methods have the same interface. Specifically,get
/options
/`head have fewer arguments than the others.There are some arguments about that these methods should not send data. But I think as an HTTP client, users should not be restricted this way. I suggest that all methods in
api.py
should have the same interface. This also would solve compatibility withrequests
as it accepts json parameter in all its methods.The text was updated successfully, but these errors were encountered: