In the next article we are going to take a look at HTTPie. This is a free, open source, command-line HTTP client for Gnu / Linux, MacOS, and Windows. This tool is intended for testing and debugging APIs, HTTP servers, and web services. It comes with JSON, HTTPS, proxies, and authentication support. It is based on Python and released under a BSD license.
HTTPie is a command line HTTP client that aims to make the CLI interaction with web services as human-friendly as possible. HTTPie is designed to test, debug, and generally interact with HTTP servers and APIs. The http and https commands allow you to create and send arbitrary HTTP requests. They use a simple syntax, and provide formatted and colored output.
If you dedicate yourself to application development, one of the usual operations is to interact with the API of other services. Currently, the services with which you interact have an API, not only to read data, but also to add or modify it. In addition to high-level developers, if you create your own scripts or applications, this tool can be useful for you. Surely in some of your scripts you have used tools like wget or curl. If this is the case you will be happy to know that HTTPie is the perfect replacement for these tools. This is so because it offers users a natural language via HTTP from the terminal.
General characteristics of HTTPie
- incluye una expressive and intuitive syntax.
- Is going to show us a formatted and colored terminal output.
- Support Built-in JSON, like the form and file uploads.
- HTTPS, proxies and authentication.
- We can use custom headers and persistent sessions.
- We will be able to carry out wget type downloads.
- Es compatible with Gnu / Linux, macOS and Windows.
- Supports the possibility to use plugins.
- Offers us a extensive documentation on the project website.
These are just some of its features. On the project's GitHub page you can consult all of them in detail.
Install HTTPie on Ubuntu
Users can install this tool on Ubuntu using apt. To do this, we will only have to open a terminal (Ctrl + Alt + T) and execute the following script:
sudo apt update && sudo apt install httpie
After the installation, we can verify installation with the following command:
http --version
We can also install this tool using its corresponding snap pack. We will only have to open a terminal (Ctrl + Alt + T) and execute the command:
sudo snap install http
This utility We can also install it using Python (works on Gnu / Linux, Windows and Mac OS X), by pip. If you don't have this package manager on your system yet, you can follow the article that we wrote on this blog a while ago.
To perform this installation, you just have to follow the instructions that describe from the project GitHub page.
Examples of use
Custom HTTP method, HTTP headers, and JSON data
http PUT httpbin.org/put X-API-Token:123 name=Ubunlog
Download file using HTTPie
http --download https://downloads.vivaldi.com/stable/vivaldi-stable_3.4.2066.106-1_amd64.deb
It can also be used as follows:
http httpbin.org/image/png > image.png
Send an HTTP method in the request
For this example we will send the GET method that is used to request data from a specific resource.
http GET httpbin.org
Send data to a form
We can also send data to a form.
http -f POST httpbin.org/post Hola=Mundo
We will have the possibility of view the request being sent using one of the output options:
http -v httpbin.org/get
Help
For get usage details, you just have to run the command:
http --help
We can also check your man pages:
man http
On the project's GitHub page, users will find more usage examples.
HTTPie is a modern, easy-to-use, cURL-like command-line HTTP client with simple, natural syntax, which also displays results in color. In this article, we have shown how to install and some simple examples of this tool running on Ubuntu 20.04. For more information, users can consult the project website.