-
-
Notifications
You must be signed in to change notification settings - Fork 858
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
Add an HTTPX cli. 😇 #1212
Add an HTTPX cli. 😇 #1212
Conversation
Feel free to mention @willmcgugan if you have any questions re the Rich side of things. :) |
Rivaling httpie in no time! |
Some TODO items...
|
def print_request_headers(request: httpx.Request) -> None: | ||
console = rich.console.Console() | ||
http_text = format_request_headers(request) | ||
syntax = rich.syntax.Syntax(http_text, "http", theme="ansi_dark", word_wrap=True) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any particular reason for going with theme="ansi_dark"
instead of background_color="default"
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Gotcha. I have a dark terminal, so I preferred the default theme. Perhaps adding a --theme={default,dark,light}
option could be an thing?
So, perhaps the route to go down here is to publish this under a separate The benefit there would be that we're not tied to bumping up |
Closing this, in favour of a little beta over here: https://github.com/encode/httpx-cli |
Given just how wonderful the
click
andrich
packages are these days, we could do some pretty wonderful stuff with anhttpx
command line tool, pretty easily.Here's a pull request that demonstrates the basics, along with a couple of examples.
Installation is
pip install httpx[cli]
.Then we get:
$ httpx https://httpbin.org/post -m POST -j '{"hello": "world"}'
Obviously there's more too it that this, in particular you'd want...
And a few bits of other functionality, such as...
--stream
- Disable formatting, and just display the content as it arrives.--upload
- Set upload content directly from a file.--download
- Download directly to a file. Default to displaying a progress bar if we're on a terminal display.--raise-for-status
- Return a non-zero error code, and display as an error, rather than the response itself.--max-redirects
,--http2
- Client-level controls that are not available inhttpx.request
, but that we might want in the cli.But some things that I think are nice about this are:
httpx
API, which I think could really help users get to grips with both of them.Normally I might think of this kind of thing as scope-creep, but if we can make it tie in really nicely, then perhaps it's just a really nice way to make
httpx
an all-round more valuable tool?Obvs. https://httpie.org/ exists and is fantastic, but I can still see the value in us presenting an alternative here, right?