17 ms·
HTTPie – A user-friendly CLI HTTP client
- gitgud 7y agoTruly one of the best cli tools out there. The api is concise and flexible, the --help flag is easy to read. But most importantly, there's sane defaults. defaults to GET request http google.com when json body exists it becomes a POST request http google.com user=65
- stephenr 7y agoI don't get how you think that second part is a "sane" default. "user=65" is not valid JSON, unless you consider it a single JSON string literal. HTTPie converts that into a JSON object. Curl will send the data literally as you send it - if you want to send JSON, give it JSON as the body. If you want to send a "Form POST" quest, give it an encoded query string as the body. If HTTPie detected that what you gave it was valid JSON, or whatever other media type, and used that to 'guess' the request Content-Type, that would be useful and smart. But HTTPie not only mangles input, it mangles it in a way that is completely non obvious. passing it "foo=bar" will send a JSON encoded object like `{"foo": "bar"}`. passing it "foo=bar&baz=boo" will still send a JSON encoded object like `{"foo": "bar"}`. So, it knows that ampersand is a field separator, but then promptly ignores all the content after it? So, no. I call bullshit on "sane defaults" when it mangles data, and silently drops data it's given.
- gorjusborg 7y agoI think it's hard not to like the HTTPie interface if you give it a bit of time. The design is brilliant.
- stephenr 7y agoI gave specific examples where it's unintuitive and your response is "The design is brilliant". Touché sir, your argument has won the day. /s
- nothrabannosir 7y agoCharitably, the emphasis could be put on “if you give it a bit of time.” Read that way, it’s not an argument for intuitive UX, just a comment about how the UX grows on you. It doesn’t contradict what you said. Should it? After all, this is a discussion forum where regular humans can share their experiences. Not debate club.
- stephenr 7y agoA design isn't "brilliant" just because "people got used to it, despite how shitty it is".
- dkersten 7y agoYou can send it raw JSON too. For example: echo '{"foo": "bar"}' | http :8000
- mike_hock 7y agoCompletely agree. Opaque magic to "guess what you want" from incomplete or plain wrong arguments isn't "sane defaults." It also doesn't make it easy to use, because eventually the magic will guess wrong and it will go from magically the right thing even though I passed garbage arguments to completely the wrong thing at the drop of a hat. An example of a "sane default" where curl falls short might be to enable redirects by default, because that is usually what the user wants (and correct client behavior).
- BoorishBears 7y ago> Opaque magic to "guess what you want" from incomplete or plain wrong arguments isn't "sane defaults." Please explain how a well-defined key-value convention is equitable to "incomplete" or "plain wrong" arguments. In what way is any of this opaque when it's fully documented and quite easy to follow?: https://github.com/jakubroztocil/httpie#id16 https://github.com/jakubroztocil/httpie#id16
- detaro 7y agoFairly sure I'd forget all the time that it thinks giving it a syntax that looks like form-encoded obviously means I want to send a JSON request.
- BoorishBears 7y agokey=value is a convention used in so many places that have nothing to do with form encoding Would Java developers see this and imagine you're passing values for a .properties file? If you've never seen the tool before, you also wouldn't know how it works at all. Once you hit help for the first time (you know, to actually learn how to use it), knowing it defaults to JSON is pretty much a base truth. It's entire value proposition seems to be stongly tied to JSON support (2nd highest feature in the pitch at the top). This is like saying you'd forget jq takes JSON strings...
- stephenr 7y ago
- gitgud 7y agoSane defaults means it is making 99% of cases that I'm using the tool easier, convention over configuration. In 99% of cases httpie can assume that I'm making a POST request or a GET request with json or query params. Very rarely will I need to add custom headers, or change the Content-Type. Yes I can explicitly define the JSON body, headers and method type every time. Or I can use a tool which uses ..... "sane defaults"
- chewz 7y agoalias wget='echo "using httpie as wget";http -d'
- buzzerbetrayed 7y agoWhy would you do this? If you want to use httpie why would type wget? If you’re pasting a snippet that uses wget, wouldn’t you want it to actually use wget? I don’t see any benefit of using this alias
- julienfr112 7y agowhat about performance ?
- petepete 7y agoI'd say that its intended use case is to familiarise yourself with APIs and test out functionality rather than use it in a place where performance really matters. I use it all the time for just that, the API is so simple I rarely need to check the docs.
- jonny383 7y agoWhen I hear "curl alternative", I think of something low-level, portable and frankly, something that will compile _almost_ anywhere that has a C compiler. But then I realized I'm thinking of libcurl, not curl. So maybe this isn't so bad in Python as a client tool. Does Python 3 still start up really slow though? (honest question)
- Myrmornis 7y agoNo, Python has never (last decade) had a startup time that is noticeable by humans when running CLI scripts, unless your CLI script is importing a large codebase. JVM languages are an example of languages which do start up too slowly to be attractive for CLI scripting. You are right that python can be horribly slow to import a large codebase, for example when starting a web server in a large django project.
- kasey_junk 7y agoAOT compilation has come back to JVM languages both on HotSpot and Graal. There are now lots of ways to remove JVM startup time penalties and most of them provide for startup times that are as fast as Python independent of code size.
- asimpletune 7y agoDoes this apply to scala?
- shakna 7y agoScala Native [0] gives you AOT via LLVM, so it isn't quite the same thing, but can, in some circumstances, significantly speed up your code. [0] https://github.com/scala-native/scala-native https://github.com/scala-native/scala-native
- chipaca 7y agoFWIW we had to move away from python in the project I was working on because just waiting for the help took more than 15 seconds (IIRC) on a beaglebone black.
- CGamesPlay 7y agoI use HTTPie all the time. It's not a curl replacement, it's a competitor in the space of CLI HTTP clients. The argument syntax is easier to use than curl, and it's geared for humans interacting with JSON APIs, including coloring and pretty printing output.
- zomglings 7y ago> I use HTTPie all the time. It's not a curl replacement, it's a competitor in the space of CLI HTTP clients. Sounds like a curl replacement to me. From wikipedia (https://en.wikipedia.org/wiki/CURL https://en.wikipedia.org/wiki/CURL): "cURL is a command-line tool for getting or sending data including files using URL syntax."
- buzzkillington 7y agoCurl is a lot more than something humans can use from the command line for http/s requests. This seems like a small tool with good ergonomics for http/s requests only.
- lol768 7y ago> Curl is a lot more than something humans can use from the command line for http/s requests. I continue to be surprised by the protocols which curl supports. SMTP, IMAP, SFTP..
- mp3geek 7y agoCan it dump all the scripts/images/etc being loaded on a specific website? (not refering to source)
- deleted 7y ago[deleted]
- laurent123456 7y agoFor someone who doesn't already know curl it might seem easier to use this, but otherwise it doesn't seem so useful. Commands are a bit shorter (as it assumes json apparently) but, when working on the terminal, once I wrote my curl command I just keep repeating it anyway or just changing one parameter.
- fanf2 7y agoI have been using curl for command line http stuff for years and years. I tried out HTTPie a few months ago for testing a json-flavoured API and I found it is amazing, it is so much less awkward than piping curl into jq and struggling with curl’s POST body options
- dkersten 7y agoI'm in the same boat. Every time I have had to use curl over the past ~15 years I've had to look up how to do the few basic things I need to do. With HTTPie, its easy enough that I haven't needed to look anything up after the first two or three times. Sure, cURL can do it and if I used it frequently enough, I guess I'd remember how to use it without having to look it up every time, but for my basic and infrequent use, HTTPie is more pleasant to me and I can remember how to use it.
- thiht 7y agoWhich curl body options are you talking about? I just see -d for the data, -XPOST which is optional when using -d, and --data-binary mostly for file transfer
- laurent123456 7y agoI'm not particularly good at memorising shell commands, but curl always felt straightforward. I use it for all kind of requests and rarely need to look up the parameters.
- l33tman 7y agoI keep using httpie for all testing and manual stuff, because with cURL (or wget) I have to continuously call up the help pages to find the correct options. In httpie it seems the philosphy is that you mostly use various non-option strings for these common additions (headers and query parameters) and I can remember these more easily :)
- zomglings 7y agoAs it looks now, I don't see much reason to switch away from curl + jq. The thing I like about curl + jq is that I can easily switch it out for: TEMPFILE=`mktemp`; curl -s <REQUEST> >$TEMPFILE; python -c "import json; f = open('$TEMPFILE', 'r'); d = json.load(f); <json processing logic and print statement>; f.close()" and run in my CI environments or ship in docker images for testing purposes. That said, I do see the potential for a tool like this. What I would like is the ability to manage different profiles for different URLs from the command line. Profiles could just be collections of header specifications - "Authorization: Bearer <blah>" or "Content-Type: application/json" (Maybe https://github.com/postmanlabs/newman#using-newman-cli https://github.com/postmanlabs/newman#using-newman-cli ? Didn't know about it until now.)
- vips7L 7y ago>TEMPFILE=`mktemp`; curl -s <REQUEST> >$TEMPFILE; python -c "import json; f = open('$TEMPFILE', 'r'); d = json.load(f); <json processing logic and print statement>; f.close()" This is painful. In powershell this is built in and as easy as iwr url/to/json | convertfrom-json | other logic
- zomglings 7y agoInteresting, looks like Linux users can also try out Powershell now: https://docs.microsoft.com/en-us/powershell/scripting/install/installing-powershell-core-on-linux?view=powershell-6 https://docs.microsoft.com/en-us/powershell/scripting/instal... It's a beefy package, though. Packaged in a docker image on top of alpine:3.10.3 following their installation instructions for alpine: https://gist.github.com/nkashy1/643e7a263054c02e2caceb3912f82f20 https://gist.github.com/nkashy1/643e7a263054c02e2caceb3912f8... The image comes in at 178 MB. alpine:3.10.3 is 5.5 MB. An alpine image in which you add bash, bash-doc, and bash-completion clocks in at 13 MB. Sounds really powerful for personal use, but not an ideal tool for production use (e.g. when you need to spin up a pod on a Kubernetes cluster to debug an issue in production). Will definitely try it out.
- vips7L 7y ago
- akvadrako 7y agoThis is pretty handy. I usually default to httpie for playing with my APIs and documenting examples - it's much clearer than curl. It doesn't seem to get much development attention though. There hasn't really been features I find useful added in the past year. The biggest issue is no support for nested JSON bodies, meaning non-trivial API calls end up just as complex as curl.
- MuffinFlavored 7y ago-H for request headers -d for body -X for method —-verbose to see response headers How much “clearer” could curl get?
- bpfrh 7y agohmmm how about this: -M for Method -B for Body -RH for Request Header you know, so you only have to know the first letter and don't have to remmeber arbitary flags? I know that it is not that easy, but unix tools do have the problem that often the flags don't make sense on the first glance.
- jbreiding 7y ago-H for header -d for data -X for execute There was a reasonable attempt at this already. There are going to opinions on either side. And through regular use the flags would become muscle memory.
- microcolonel 7y ago> I know that it is not that easy, but unix tools do have the problem that often the flags don't make sense on the first glance. Should you be sending HTTP requests to something without knowing precisely what you're doing? httpie just sorta assumes from your arguments what you're trying to do, and for me it has often been wrong. Probably works OK if you have a mostly read-only API.
- bpfrh 7y ago
- devnonymous 7y agoThose who like HTTPie might also like http-prompt[1] which is an interactive prompt built on top of it. [1] http://http-prompt.com/ http://http-prompt.com/
- johnjungles 7y agoThis is one of the best cli tool I loved it 4 years ago and still do
- dxxvi 7y agoThere's at least 1 thing curl can do but httpie cannot: anyauth where curl sends a request and based on the response curl will send another request with the correct authentication format.
- izolate 7y agoThis is the gold standard of CLI tools. Sure, cURL may technically be more capable, but HTTPie is friendier, more memorable, and clearly built with developer UX in mind.
- wwn_se 7y agoIt's the other way around, curl is so good its amost like using the spec. directly
- fluxsauce 7y agoI really like it for functional testing and for describing steps in peer reviews; it's concise and readable. It's not the only tool out there; sometimes cURL makes more sense depending on the context. Use the right tool for the right job!
- tbrock 7y agoWonderful tool. I’ve said this before but something holding it back is that you need python to run it and have a python environment set up. Usually this isn't that big of a deal but it’s just enough friction to make me not reach for it most of the time. Conversely something like jq is trivial to install and use almost anywhere because it is just a binary linked against libc. As a result I use it all the time.
- divbzero 7y agoThe Python dependency for HTTPie is handled by most Linux and macOS package managers [1]. It would be great to have it in Windows package managers as well. [1]: https://httpie.org/doc#installation https://httpie.org/doc#installation
- ducaale 7y agoOne time I tried to install HTTPie from ubuntu 16.04 apt repository I got an old version that was not compatible with httpie-jwt-auth so I had to install it using pip. 1. pip3 install httpie. 2. python3 -m pip install httpie. 3. sudo pip install httpie. Finally, it was working. Last week I upgraded to ubuntu 18.04 and surprise, httpie is not working. I didn't bother installing again from pip. Luckily this time, apt repository had a recent version. Scrolling back through my terminal history, I see that I went through the same struggle with s3cmd. So yeah, installing anything that requires python is a bit painful. Fortunately, someone in the comments mentioned https://github.com/rs/curlie https://github.com/rs/curlie which is an HTTPie alternative in golang.
- rochacon 7y agoHTTPie is amazing, but I grew tired of it being "slow", slower than some of my services response times at least. Migrated to Curlie [1], `alias http=curlie`, and been happy with it since. Same API, better performance and access to full `curl` flags. [1] https://curlie.io https://curlie.io
- kjsthree 7y ago> Like curl but unlike httpie, headers are written on stderr instead of stdout. What’s the thinking here? If I ask for the headers, wouldn’t I want that on stdout?
- Arnavion 7y agoThe examples show that the headers are printed by default, so writing them to stderr is the correct behavior.
- kjsthree 7y agoWriting by default is logically followed by stderr? I just don’t follow. Asking a program for info and then getting that info on stderr seems really bizarre to me. Is this some historical UNIXism?
- unilynx 7y agoA lot of command line tools send debugging output to stderr so you can build a pipe/redirect output and still see the debug and error outputs. You could consider headers to be some sort of debug prints..
- Arnavion 7y ago>Asking a program for info and then getting that info on stderr seems really bizarre to me. The info that you're asking the program for is the response body. You're using `curl` / `curlie` primarily to get the response body and then pipe it to the rest of the command. The headers are ancillary. If the headers were the info you were asking for, eg when running `curl -D -`, then yes they should get printed to stdout. That is not the case being considered here.
- dig1 7y agoFor those using Emacs, I'd recommend restclient.el [1]. In Emacs fashion, you can keep REST API documented in a single (or more) files and evaluate parts directly in buffer for testing and playing. Throw that on git/mercurial and you have versioned and documented REST API ;) [1] https://github.com/pashky/restclient.el https://github.com/pashky/restclient.el
- t0astbread 7y agoVisual Studio Code has a similarly named (seemingly?) API-compatible extension: https://github.com/Huachao/vscode-restclient https://github.com/Huachao/vscode-restclient
- dang 7y agoThe major previous threads are 2018: https://news.ycombinator.com/item?id=16243700 https://news.ycombinator.com/item?id=16243700 2016: https://news.ycombinator.com/item?id=12283365 https://news.ycombinator.com/item?id=12283365 https://news.ycombinator.com/item?id=11859777 https://news.ycombinator.com/item?id=11859777 2015: https://news.ycombinator.com/item?id=10418882 https://news.ycombinator.com/item?id=10418882 2014: https://news.ycombinator.com/item?id=7890367 https://news.ycombinator.com/item?id=7890367 2012: https://news.ycombinator.com/item?id=4261263 https://news.ycombinator.com/item?id=4261263
- t0astbread 7y agoA wonderful program. Apparently this is a hot topic but I've found this tool after growing frustrated with how verbose curl is to type for simply trying out JSON APIs interactively. Combined with something like fx[1] this is a real treat. [1] https://github.com/antonmedv/fx https://github.com/antonmedv/fx