Make no mistake: for people who hack on UNIX-based systems,
curl is a really powerful command. It enables you to extract the client-side content of any web page in an instant and also to do all kinds of things with the result, like dumping it into a .txt file (a trick which has been extremely useful to me in learning web development).
But the curl command doesn’t always function all that intuitively on the input side, and the output always comes out monochromatic, making it difficult to immediately discern what’s going on in the stream of text you’re presented with in the CLI.
HTTPie, in the words of its creator, was built “out of frustration with existing tools.” It provides the capacity to make both more intuitive requests and polychromatic output. Using it couldn’t be any more simple. The commands underlying an HTTPie request look like this in generic form:
Let’s have a look at a sample POST request (taken from HTTPie’s GitHub readme):
http [flags] [METHOD] URL [items]
The equivalent request done with the curl command:
http --form POST api.example.org/person/1 name=’John Smith’ email@example.com
Requests in HTTPie aren’t necessarily significantly less verbose than curl requests. But that’s not their primary function. The benefit of HTTPie is that its requests are more intuitive. For example, in the example above, HTTPie automatically transformed the form data into
curl --data “name=John+Smith&email=john%40example.org” api.example.org/person/1
For someone that hasn’t spent years using the
curl command, HTTPie has made HTTP requests from the command line far more intuitive. But where it truly shines, even for people who are deeply experienced using the curl command, is on the output side. The curl command always returns monochrome output. HTTPie, on the other hand, returns a profusion of gray, orange, purple, blue, and more.
If I run http
GET http://www.doesntexist.com/ in HTTPie, I get the following output:
For me at least, this kind of polychromatic output has had a way of transforming the whole CLI-web interface.
One potential downside to be aware of: if you use it in conjunction with a more command in a command pipeline, you will use the sleek coloration that you otherwise get. This makes the tool somewhat less useful. Here’s to hoping that this is changed in later versions.
On the installation side, HTTPie is just a Python module, and installing it is a cinch. If you’re using pip, just run
pip install httpie and that will enable you to start making HTTP requests in the CLI once the installation is finished.
There is a lot more to HTTPie, so I suggest reading the docs and experimenting with it yourself, if only for the most shallow reason of all: pretty colors traipsing across your console.