Using HTTPie on Linux

0
301

If you are a sysadmin or you are starting to be a sysadmin, it is normal to use the terminal too much. And you know that the terminal is one of the most powerful tools in all of Linux. Recently I showed you the many things that can be done with CURL and we even use it a lot in our tutorials. However, there is an application that pretends to be a reliable alternative to CURL. So, in this post, I will tell you about HTTPie. Using HTTPie is simple, you will see.

HTTPie is a command line HTTP client with an intuitive UI, JSON support, syntax highlighting, wget-like downloads, plugins, and more. Its goal is to make CLI interaction with web services as human-friendly as possible. In addition, HTTPie can be used for testing, debugging, and generally interacting with HTTP servers.

The mainly features are:

  • Wget-like downloads.
  • Python 2.7 and 3.x support.
  • Linux, macOS and Windows support.
  • Plugins.
  • Sensible defaults.
  • Expressive and intuitive command syntax.
  • Colorized and formatted terminal output.
  • Built-in JSON support.
  • Persistent sessions.
  • Forms and file uploads.

So, let us start.

Installing HTTPie

HTTPie is an application that is available in the main repositories of most Linux distributions. So, there is no major complication.

If you are using Debian, Ubuntu or derivates:

sudo apt install httpie

So, in case you are using Fedora:

sudo dnf install httpie

On CentOS / and RHEL:

sudo yum install httpie

Finally, if you are using Arch Linux o derivates:

sudo pacman -S httpie
Install httpie
Install httpie

Using HTTPie on Linux

HTTPie is not complicated to use. On the contrary, its syntax is quite simple to take advantage of. Its syntax is mainly like this:

http [flags] [METHOD] URL [ITEM [ITEM]]

However, if you run the following command, you will see all the options.

http --help
Showing the HTTPie help
Showing the HTTPie help

Let us see some examples.

Basic usage

The most basic way to use HTTPie is as follows:

http somepage.com
Basic usage
Basic usage

You can add th -v option to see other information about the site.

http -v somepage.com
Add a option to the command
Add a option to the command

Download a file with HTTPie

Similar to CURL with HTTPie it is possible to download a file. For this you can use this command:

http page.com/file > fileo

Where fileo is the name will be downloaded.

Or you can also use the wget way.

http --download page.com/file
Download a file using HTTPie
Download a file using HTTPie

So, this is how to download a file with HTTPie.

Upload a file

If you can download a file with HTTPie, obviously you can upload a file.

http example.com < file.odt

It is a very useful option to interact with servers, even homemade ones.

Submitting form

An interesting option is that you can interact with HTML forms. Imagine the possibilities. To do this, run this command.

http -f POST page.com input="value"

Basic authentication with HTTPie

Next, as part of the interaction with servers and applications, you can perform basic authentication from the console with HTTPie.

http -a username:password page.com

So, that’s all.

Conclusion

It’s good that sysadmin have CLI tools that facilitate some HTTP interaction processes. Therefore, HTTPie is presented as a great alternative to CURL and that’s why we win the users.

Please share this post with others.

LEAVE A REPLY

Please enter your comment!
Please enter your name here