HTTPie CLI docs

Contents…

HTTPie (pronounced aitch-tee-tee-pie) is a command-line HTTP client. Its goal is to make CLI interaction with web services as human-friendly as possible. HTTPie is designed for testing, debugging, and generally interacting with APIs & HTTP servers. The http & https commands allow for creating and sending arbitrary HTTP requests. They use simple and natural syntax and provide formatted and colorized output.

Main features

  • Expressive and intuitive syntax
  • Formatted and colorized terminal output
  • Built-in JSON support
  • Forms and file uploads
  • HTTPS, proxies, and authentication
  • Arbitrary request data
  • Custom headers
  • Persistent sessions
  • Wget-like downloads
  • Linux, macOS, Windows, and FreeBSD support
  • Plugins
  • Documentation
  • Test coverage

Installation

Universal

PyPI

Please make sure you have Python 3.7 or newer (python --version).

# Install httpie
$ python -m pip install --upgrade pip wheel
$ python -m pip install httpie
# Upgrade httpie
$ python -m pip install --upgrade pip wheel
$ python -m pip install --upgrade httpie

macOS

Homebrew

To install Homebrew, see its installation.

# Install httpie
$ brew update
$ brew install httpie
# Upgrade httpie
$ brew update
$ brew upgrade httpie

MacPorts

To install MacPorts, see its installation.

# Install httpie
$ port selfupdate
$ port install httpie
# Upgrade httpie
$ port selfupdate
$ port upgrade httpie

Windows

Chocolatey

To install Chocolatey, see its installation.

# Install httpie
$ choco install httpie
Run
# Upgrade httpie
$ choco upgrade httpie
Run

Linux

Debian and Ubuntu

Also works for other Debian-derived distributions like MX Linux, Linux Mint, deepin, Pop!_OS, KDE neon, Zorin OS, elementary OS, Kubuntu, Devuan, Linux Lite, Peppermint OS, Lubuntu, antiX, Xubuntu, etc.

# Install httpie
$ curl -SsL https://packages.httpie.io/deb/KEY.gpg | sudo gpg --dearmor -o /usr/share/keyrings/httpie.gpg
$ echo "deb [arch=amd64 signed-by=/usr/share/keyrings/httpie.gpg] https://packages.httpie.io/deb ./" | sudo tee /etc/apt/sources.list.d/httpie.list > /dev/null
$ sudo apt update
$ sudo apt install httpie
# Upgrade httpie
$ sudo apt update && sudo apt upgrade httpie
Run

Fedora

# Install httpie
$ dnf install httpie
Run
# Upgrade httpie
$ dnf upgrade httpie
Run

CentOS and RHEL

Also works for other RHEL-derived distributions like ClearOS, Oracle Linux, etc.

# Install httpie
$ yum install epel-release
$ yum install httpie
# Upgrade httpie
$ yum upgrade httpie
Run

Single binary executables

Get the standalone HTTPie Linux executables when you don't want to go through the full installation process.

# Install httpie
$ https --download packages.httpie.io/binaries/linux/http-latest -o http
$ ln -ls ./http ./https
$ chmod +x ./http ./https
# Upgrade httpie
$ https --download packages.httpie.io/binaries/linux/http-latest -o http
Run

Snapcraft (Linux)

To install Snapcraft, see its installation.

# Install httpie
$ snap install httpie
Run
# Upgrade httpie
$ snap refresh httpie
Run

Linuxbrew

To install Linuxbrew, see its installation.

# Install httpie
$ brew update
$ brew install httpie
# Upgrade httpie
$ brew update
$ brew upgrade httpie

Arch Linux

Also works for other Arch-derived distributions like ArcoLinux, EndeavourOS, Artix Linux, etc.

# Install httpie
$ pacman -Syu httpie
Run
# Upgrade httpie
$ pacman -Syu

FreeBSD

FreshPorts

# Install httpie
$ pkg install www/py-httpie
Run
# Upgrade httpie
$ pkg upgrade www/py-httpie
Run

Unstable version

If you want to try out the latest version of HTTPie that hasn't been officially released yet, you can install the development or unstable version directly from the master branch on GitHub. However, keep in mind that the development version is a work in progress and may not be as reliable as the stable version.

You can use the following command to install the development version of HTTPie on Linux, macOS, Windows, or FreeBSD operating systems. With this command, the code present in the master branch is downloaded and installed using pip.

$ python -m pip install --upgrade https://github.com/httpie/cli/archive/master.tar.gz
Run

There are other ways to install the development version of HTTPie on macOS and Linux.

You can install it using Homebrew by running the following commands:

$ brew uninstall --force httpie
$ brew install --HEAD httpie

You can install it using Snapcraft by running the following commands:

$ snap remove httpie
$ snap install httpie --edge

To verify the installation, you can compare the version identifier on GitHub with the one available on your machine. You can check the version of HTTPie on your machine by using the command http --version.

$ http --version
# 3.X.X.dev0
Run

Note that on your machine, the version name will have the .dev0 suffix.

Usage

Hello World:

$ https httpie.io/hello
Run

Synopsis:

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

See also http --help (and for systems where man pages are available, you can use man http).

Examples

Custom HTTP method, HTTP headers and JSON data:

$ http PUT pie.dev/put X-API-Token:123 name=John
Run

Submitting forms:

$ http -f POST pie.dev/post hello=World
Run

See the request that is being sent using one of the output options:

$ http -v pie.dev/get
Run

Build and print a request without sending it using offline mode:

$ http --offline pie.dev/post hello=offline
Run

Use GitHub API to post a comment on an issue with authentication:

$ http -a USERNAME POST https://api.github.com/repos/httpie/cli/issues/83/comments body='HTTPie is awesome! :heart:'
Run

Upload a file using redirected input:

$ http pie.dev/post < files/data.json
Run

Download a file and save it via redirected output:

$ http pie.dev/image/png > image.png
Run

Download a file wget style:

$ http --download pie.dev/image/png
Run

Use named sessions to make certain aspects of the communication persistent between requests to the same host:

$ http --session=logged-in -a username:password pie.dev/get API-Key:123
Run
$ http --session=logged-in pie.dev/headers
Run

Set a custom Host header to work around missing DNS records:

$ http localhost:8000 Host:example.com
Run

HTTP method

The name of the HTTP method comes right before the URL argument:

$ http DELETE pie.dev/delete
Run

Which looks similar to the actual Request-Line that is sent:

DELETE /delete HTTP/1.1

In addition to the standard methods (GET, POST, HEAD, PUT, PATCH, DELETE, etc.), you can use custom method names, for example:

$ http AHOY pie.dev/post
Run

There are no restrictions regarding which request methods can include a body. You can send an empty POST request:

$ http POST pie.dev/post
Run

You can also make GET requests containing a body:

$ http GET pie.dev/get hello=world
Run

Optional GET and POST

The METHOD argument is optional, and when you don’t specify it, HTTPie defaults to:

  • GET for requests without body
  • POST for requests with body

Here we don’t specify any request data, so both commands will send the same GET request:

$ http GET pie.dev/get
Run
$ http pie.dev/get
Run

Here, on the other hand, we do have some data, so both commands will make the same POST request:

$ http POST pie.dev/post hello=world
Run
$ http pie.dev/post hello=world
Run

Request URL

The only information HTTPie needs to perform a request is a URL.

The default scheme is http:// and can be omitted from the argument:

$ http example.org
# → http://example.org
Run

HTTPie also installs an https executable, where the default scheme is https://:

$ https example.org
# → https://example.org
Run

When you paste a URL into the terminal, you can even keep the :// bit in the URL argument to quickly convert the URL into an HTTPie call just by adding a space after the protocol name.

$ https ://example.org
# → https://example.org
Run
$ http ://example.org
# → http://example.org
Run

Querystring parameters

If you find yourself manually constructing URLs with querystring parameters on the terminal, you may appreciate the param==value syntax for appending URL parameters.

With that, you don’t have to worry about escaping the & separators for your shell. Additionally, any special characters in the parameter name or value get automatically URL-escaped (as opposed to the parameters specified in the full URL, which HTTPie doesn’t modify).

$ http https://api.github.com/search/repositories q==httpie per_page==1
Run
GET /search/repositories?q=httpie&per_page=1 HTTP/1.1

You can even retrieve the value from a file by using the param==@file syntax. This would also effectively strip the newlines from the end. See file based separators for more examples.

$ http pie.dev/get text==@files/text.txt
Run

URL shortcuts for localhost

Additionally, curl-like shorthand for localhost is supported. This means that, for example, :3000 would expand to http://localhost:3000. If the port is omitted, then port 80 is assumed.

$ http :/foo
Run
GET /foo HTTP/1.1
Host: localhost
$ http :3000/bar
Run
GET /bar HTTP/1.1
Host: localhost:3000
$ http :
Run
GET / HTTP/1.1
Host: localhost

Other default schemes

When HTTPie is invoked as https then the default scheme is https:// ($ https example.org will make a request to https://example.org).

You can also use the --default-scheme <URL_SCHEME> option to create shortcuts for other protocols than HTTP (possibly supported via plugins). Example for the httpie-unixsocket plugin:

# Before
$ http http+unix://%2Fvar%2Frun%2Fdocker.sock/info
Run
# Create an alias
$ alias http-unix='http --default-scheme="http+unix"'
Run
# Now the scheme can be omitted
$ http-unix %2Fvar%2Frun%2Fdocker.sock/info
Run

--path-as-is

The standard behavior of HTTP clients is to normalize the path portion of URLs by squashing dot segments as a typical filesystem would:

$ http -v example.org/./../../etc/password
Run
GET /etc/password HTTP/1.1

The --path-as-is option allows you to disable this behavior:

$ http --path-as-is -v example.org/./../../etc/password
Run
GET /../../etc/password HTTP/1.1

Request items

There are a few different request item types that provide a convenient mechanism for specifying HTTP headers, JSON and form data, files, and URL parameters. This is a very practical way of constructing HTTP requests from scratch on the CLI.

Each request item is simply a key/value pair separated with the following characters: : (headers), = (data field, e.g., JSON, form), := (raw data field) == (query parameters), @ (file upload).

$ http PUT pie.dev/put \
    X-Date:today \                     # Header
    token==secret \                    # Query parameter
    name=John \                        # Data field
    age:=29                            # Raw JSON
Run