httpie - A Curl Alternative HTTP Command Line Client on Linux

httpie http clientIn this article, I will show you httpie which is a modern command line HTTP client an alternative tool for curl. httpie is a GitHub project of Jakub Roztocil which has benefited some contributions on Github. The httpie tool is seen as a modern command line http client which makes CLI interaction with web services and provides http command that allows for sending arbitrary HTTP requests using a simple and natural syntax, and displays colorized output.

It offers supports some features as a built-in JSON, HTTPS, syntax colorization, proxies, authentication, persistent sessions, a good support of Python (2.6, 2.7 and 3.x) and some other that you can discover.

1) Install httpie

By default, httpie is present on your Linux repository and can be installed directly via the packages

# yum install httpie
Loaded plugins: fastestmirror
base                                                                                                                           | 3.6 kB  00:00:00     
epel/x86_64/metalink                                                                                                           |  13 kB  00:00:00     
epel                                                                                                                           | 4.3 kB  00:00:00     
Dependencies Resolved

 Package                               Arch                         Version                                          Repository                  Size
 python2-httpie                        noarch                       0.9.4-1.el7                                      epel                       100 k
Installing for dependencies:
 jbigkit-libs                          x86_64                       2.0-11.el7                                       base                        46 k
 libtiff                               x86_64                       4.0.3-27.el7_3                                   base                       170 k
 libwebp                               x86_64                       0.3.0-7.el7                                      base                       170 k
 python-chardet                        noarch                       2.2.1-1.el7_1                                    base                       227 k

  python2-httpie.noarch 0:0.9.4-1.el7                                                                                                                 

Dependency Installed:
  jbigkit-libs.x86_64 0:2.0-11.el7               libtiff.x86_64 0:4.0.3-27.el7_3                        libwebp.x86_64 0:0.3.0-7.el7                
  python-chardet.noarch 0:2.2.1-1.el7_1          python-pillow.x86_64 0:2.0.0-19.gitd1c6db8.el7         python-pygments.noarch 0:1.4-10.el7         
  python-requests.noarch 0:2.6.0-1.el7_1         python-six.noarch 0:1.9.0-2.el7                        python-urllib3.noarch 0:1.10.2-3.el7        


2) How to use httpie

Now that we have installed httpie, we must retain below syntax.

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

And we can see how to use it with the help command

# http --help
usage: http [--json] [--form] [--pretty {all,colors,format,none}]
            [--style STYLE] [--print WHAT] [--headers] [--body] [--verbose]
            [--all] [--history-print WHAT] [--stream] [--output FILE]
            [--download] [--continue]
            [--session SESSION_NAME_OR_PATH | --session-read-only SESSION_NAME_OR_PATH]
            [--auth USER[:PASS]] [--auth-type {basic,digest}]
            [--proxy PROTOCOL:PROXY_URL] [--follow]
            [--max-redirects MAX_REDIRECTS] [--timeout SECONDS]
            [--check-status] [--verify VERIFY]
            [--ssl {ssl2.3,ssl3,tls1,tls1.1,tls1.2}] [--cert CERT]
            [--cert-key CERT_KEY] [--ignore-stdin] [--help] [--version]
            [--traceback] [--debug]

HTTPie - a CLI, cURL-like tool for humans. <>

      The HTTP method to be used for the request (GET, POST, PUT, DELETE, ...).
      This argument can be omitted in which case HTTPie will use POST if there
      is some data to be sent, otherwise GET:
          $ http               # => GET
          $ http hello=world   # => POST

The required argument is the URL in order to use the command. For example, you can use httpie to post a comment on a site directly through your terminal as below:

# http -a USERNAME POST body='HTTPie is awesome! :heart:'

You can check the result directly to the github issue post page of the project

a) Request URL

The basic usage of httpie is to request website URL.

# http

b) Download a file

You can download a file with the --download parameter of htppie. It works as wget command

# http --download

It is possible to directly rename the downloaded file during the process with the-o parameter as below:

# http --download -o kubernetes.jpg

When you use the -o parameter, you can resume the download with the -c parameter

c) Authenticate to the URL

httpie supports authentication through two methods: the basic and digest authentication. You have the possibility to directly insert the password on the terminal during the process but you can also choose for your password to be prompted during the process. For the basic authentication with password prompted, do as below:

# http -a alainfrancois
http: password for

Or you can directly use your password as below:

# http -a alainfrancois:password

Some additional authentication mechanism can be installed as plugins such as AWS / Amazon S3 (httpie-aws-auth) or JWTAuth (httpie-jwt-auth).

d) Create a session

httpie has the particularity to support persistent sessions. You can create named sessions, anonymous and read-only sessions.

You can create one or more named session per host as below:

# http --session=user1 -a user1:password X-Foo:Bar

e) Sending request

One of the things you can add to the request with request items are GET parameters as below:

# http foo==bar wicked==witch

httpie is a great tool which can do the same work as curl. You can directly go to the official GitHub project for more information.

About Alain Francois

IT Linux administrator passionate of free and open source software, I work on Linux Systems since some years on installations and deployments of certain solutions. I like to share my experiences with a wider audience by training and conferences.

Author Archive Page

Have anything to say?

Your email address will not be published. Required fields are marked *

All comments are subject to moderation.