1. Library
  2. Computer Networks
  3. Tools and Commands
  4. Http Testing

Updated 8 hours ago

HTTPie (pronounced "aitch-tee-tee-pie") is a command-line HTTP client that does what curl does, but designed for humans instead of scripts.

The difference isn't features. It's philosophy. curl makes you speak its language. HTTPie speaks yours.

The Difference in Practice

Sending a POST request with JSON data and an auth header:

curl:

curl -X POST https://api.example.com/users \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer token123" \
  -d '{"name":"John","email":"john@example.com"}'

HTTPie:

http POST api.example.com/users \
  Authorization:"Bearer token123" \
  name=John email=john@example.com

HTTPie figures out that you want JSON (because who doesn't?), that you want HTTPS (because it's not 2005), and that name=John means {"name": "John"} (because of course it does).

Installation

# macOS
brew install httpie

# Ubuntu/Debian
sudo apt install httpie

# Anywhere with Python
pip install httpie

The Syntax

The pattern: http [METHOD] URL [ITEMS]

# GET is assumed
http api.example.com/users

# POST with data
http POST api.example.com/users name=John age:=30

# Any method works
http PUT api.example.com/users/123 name="Updated"
http DELETE api.example.com/users/123

The Operators

HTTPie uses different operators for different things. This looks arbitrary until you see the logic:

OperatorMeaningExample
=String valuename=John"name": "John"
:=Raw JSONage:=30"age": 30
==Query parameterq==test?q=test
:HeaderAuthorization:"Bearer x"

The colon in := means "this is literal"—a number, boolean, array, or object. Without it, everything becomes a string.

http POST api.example.com/users \
  name=John \
  age:=30 \
  active:=true \
  tags:='["developer","writer"]'

Generates:

{
  "name": "John",
  "age": 30,
  "active": true,
  "tags": ["developer", "writer"]
}

Headers

The colon separator distinguishes headers from data:

http api.example.com/data \
  Authorization:"Bearer token123" \
  Accept:application/json

No -H flag. HTTPie sees the colon and knows.

Query Parameters

Double-equals puts it in the URL:

http api.example.com/search q==test limit==10 sort==date
# → api.example.com/search?q=test&limit=10&sort=date

Authentication

# Basic auth
http -a username:password api.example.com/secure

# Bearer token (just a header)
http api.example.com/data Authorization:"Bearer token123"

Form Data and File Uploads

# Form data
http --form POST api.example.com/login username=john password=secret

# File upload
http --form POST api.example.com/upload file@document.pdf title="My Doc"

Controlling Output

HTTPie colorizes and formats JSON automatically. Control what you see with -p:

  • H = request headers
  • B = request body
  • h = response headers
  • b = response body
# See everything
http -v POST api.example.com/users name=John

# Just response headers
http -p h api.example.com

# Just response body (for piping to jq)
http -p b api.example.com/data

Sessions

Persist cookies and auth across requests:

# Login and save session
http --session=myapp POST api.example.com/login \
  username=john password=secret

# Subsequent requests use the session
http --session=myapp GET api.example.com/dashboard
http --session=myapp POST api.example.com/posts title="New Post"

Sessions live in ~/.httpie/sessions/.

Downloading Files

http --download api.example.com/report.pdf
http --download -o custom-name.pdf api.example.com/report.pdf

Other Options

# Follow redirects
http --follow api.example.com/redirect

# Set timeout
http --timeout=5 api.example.com/slow

# Skip SSL verification (testing only)
http --verify=no api.example.com

# Use a proxy
http --proxy=http:http://proxy.example.com:8080 api.example.com

In Scripts

HTTPie is designed for humans, but it works in scripts:

# Check if API is healthy
if http --check-status api.example.com/health > /dev/null 2>&1; then
  echo "API is up"
fi

# Extract a field with jq
http api.example.com/users/123 | jq -r '.name'

HTTPie vs. curl

Use HTTPie when:

  • Testing APIs interactively
  • Exploring a new API
  • You want readable, colorized output
  • You're tired of escaping JSON in quotes

Use curl when:

  • Writing scripts (curl's output is more predictable)
  • You can't install additional tools
  • You need non-HTTP protocols
  • It's already in the system

They solve the same problem for different audiences. curl optimizes for machines and scripts. HTTPie optimizes for the human at the keyboard.

Frequently Asked Questions About HTTPie

Was this page helpful?

😔
🤨
😃