HTTPie (pronounced "aitch-tee-tee-pee") is a command-line HTTP client that makes CLI interaction with web services as user-friendly as possible. It provides a simple interface for sending HTTP requests using intuitive syntax, with beautiful and colorful terminal output. If you've been using curl but find its syntax cumbersome, HTTPie might be the upgrade you've been looking for.
Before diving into the details, let's understand why HTTPie has gained popularity among developers, DevOps engineers, and system administrators:
HTTPie is available on most platforms. Here's how to install it on various systems:
brew install httpie
apt-get update
apt-get install httpie
dnf install httpie
yum install epel-release
yum install httpie
pacman -S httpie
Using Chocolatey:
choco install httpie
Using Scoop:
scoop install httpie
pip install --upgrade httpie
git clone https://github.com/httpie/httpie.git
cd httpie
pip install -e .
The basic syntax for HTTPie is:
http [flags] [METHOD] URL [ITEM [ITEM]]
Where:
[flags]
are optional parameters that modify the request behavior[METHOD]
is the HTTP method (default: GET)URL
is the target URL[ITEM]
can be headers, query parameters, data fields, etc.# Basic GET request
http httpie.io/hello
# Explicit GET request
http GET httpie.io/get
# Other HTTP methods
http POST httpie.io/post
http PUT httpie.io/put
http DELETE httpie.io/delete
http PATCH httpie.io/patch
HTTPie makes it easy to specify different types of request data.
Add custom headers using the Header:Value
syntax:
http example.com User-Agent:MyClient X-API-Token:abc123
Add URL parameters with the ==
syntax:
http example.com/api search==python language==en
This sends a request to example.com/api?search=python&language=en
HTTPie sends JSON by default. Use the =
syntax for string values:
http POST api.example.com/users name=John age:=30 is_member:=true
Note the difference:
name=John
: String value ("John")age:=30
: Raw JSON number (30)is_member:=true
: Boolean value (true)Send form data with the -f
or --form
flag:
http --form POST api.example.com/users name="John Doe" email=john@example.com
Upload files using the @
syntax:
# Text file
http --form POST api.example.com/upload file@/path/to/file.txt
# Binary file with content type
http --form POST api.example.com/upload file@/path/to/image.jpg;type=image/jpeg
HTTPie supports various authentication methods:
# Using credentials directly
http -a username:password example.com
# Using URL format
http username:password@example.com
http example.com "Authorization: Bearer token123"
http --auth-type=digest -a username:password example.com
http --method=PURGE example.com
http -F example.com
# or
http --follow example.com
http --timeout=30 example.com
# Save to file
http example.com > response.json
# Download mode
http --download example.com/file.zip
# Headers only
http --headers example.com
# Body only
http --body example.com
# Verbose output
http -v example.com
# Extra verbose
http -vv example.com
HTTPie can maintain sessions between requests:
# Login and save session
http --session=logged-in -a username:password example.com/login
# Use saved session
http --session=logged-in example.com/dashboard
HTTPie shines when working with APIs. Here are some common patterns:
# Create a resource (POST)
http POST api.example.com/posts title="Hello World" body="This is my first post" userId:=1
# Retrieve a resource (GET)
http api.example.com/posts/1
# Update a resource (PUT/PATCH)
http PATCH api.example.com/posts/1 title="Updated Title"
# Delete a resource (DELETE)
http DELETE api.example.com/posts/1
http POST api.example.com/graphql query='{ user(id: 1) { name, email } }'
Using the HTTPie CLI extension httpie-websocket
:
pip install httpie-websocket
http --ws ws://echo.websocket.org
HTTPie can be customized through configuration files.
~/.config/httpie/config.json
~/.config/httpie/sessions/<host>/<n>.json
{
"default_options": [
"--style=monokai",
"--follow",
"--timeout=30",
"--verify=no"
],
"implicit_content_type": "json"
}
Option | Description |
---|---|
-m, --method METHOD |
Specify HTTP method |
--follow, -F |
Follow redirects |
--verify VERIFY |
SSL verification mode |
--ssl=SSL_VERSION |
Specify SSL version |
--cert CERT |
SSL client certificate |
--cert-key CERT_KEY |
SSL client certificate key |
--ignore-netrc |
Ignore credentials from .netrc |
--proxy PROXY |
Specify proxy |
--http-version HTTP_VERSION |
HTTP version (1.0/1.1/2) |
--cookies |
Enable cookies |
Option | Description |
---|---|
-a, --auth USER:PASS |
Authentication credentials |
--auth-type AUTH_TYPE |
Authentication mechanism |
--bearer TOKEN |
Bearer token |
Option | Description |
---|---|
-j, --json |
Data as JSON (default) |
-f, --form |
Data as form |
--multipart |
Multipart form data |
-b, --body BODY |
Raw request body |
--compress |
Compress request body |
-c, --content-type CONTENT_TYPE |
Override content type |
Option | Description |
---|---|
-p, --print WHAT |
What parts to print |
-h, --headers |
Print only headers |
-b, --body |
Print only body |
-v, --verbose |
Verbose output |
-q, --quiet |
Quieter output |
-S, --stream |
Stream response body |
-o, --output FILE |
Save output to file |
-d, --download |
Download mode |
--pretty STYLE |
Output processing |
--style STYLE |
Output coloring style |
Option | Description |
---|---|
-s, --session SESSION_NAME |
Use session |
--session-read-only SESSION |
Use read-only session |
Option | Description |
---|---|
--help |
Show help |
--version |
Show version |
--traceback |
Show exception traceback |
--debug |
Show debugging information |
HTTPie offers tools for processing and filtering responses.
Combine HTTPie with jq
for powerful JSON processing:
http api.example.com/users | jq '.[] | select(.active==true)'
Extract specific headers for scripting:
token=$(http -b POST api.example.com/auth username=admin password=secret | jq -r .token)
http api.example.com/secure "Authorization: Bearer $token"
HTTPie's functionality can be extended with plugins:
Plugin | Description | Installation |
---|---|---|
httpie-jwt-auth |
JWT authentication | pip install httpie-jwt-auth |
httpie-oauth |
OAuth support | pip install httpie-oauth |
httpie-aws-auth |
AWS authentication | pip install httpie-aws-auth |
httpie-unixsocket |
Unix socket support | pip install httpie-unixsocket |
http --auth-type=jwt --auth=my_token api.example.com
While both are HTTP clients, they have different strengths:
Feature | HTTPie | cURL |
---|---|---|
Syntax | User-friendly | Powerful but complex |
Defaults | Sensible defaults | Requires explicit options |
Output | Colorized by default | Raw by default |
JSON handling | Built-in | Requires formatting |
Learning curve | Gentle | Steeper |
Availability | Modern systems | Nearly universal |
http --verify=no example.com
http -v example.com
http --timeout=60 example.com
http --print=Hb example.com
HTTPie has revolutionized command-line HTTP interactions with its intuitive syntax and beautiful output. Whether you're a developer testing APIs, a DevOps engineer automating infrastructure, or a system administrator troubleshooting services, HTTPie offers a more pleasant experience than traditional tools.
The combination of sensible defaults, powerful capabilities, and extensibility makes HTTPie an essential tool in any modern developer's toolkit. As web APIs continue to proliferate, having a tool that makes HTTP interactions more human-friendly becomes increasingly valuable.
Thank you for reading this comprehensive guide to HTTPie. We hope it helps you master this powerful tool and enhances your command-line productivity when working with HTTP services and APIs.