HTTPie
GitHub Overview
httpie/cli
🥧 HTTPie CLI — modern, user-friendly command-line HTTP client for the API era. JSON support, colors, sessions, downloads, plugins & more.
Topics
Star History
Development Tool
HTTPie
Overview
HTTPie is a human-friendly command-line HTTP client. With intuitive syntax and JSON support, it serves as a modern alternative to cURL beloved by developers. Beautiful output formatting, rich authentication support, and clear grammar significantly improve productivity in API development.
Details
HTTPie was designed as a modern command-line HTTP client suitable for the API era. Compared to cURL, it adopts human-readable and writable syntax, making HTTP request creation intuitive. From simple syntax like http GET example.com
to complex requests like http PUT api.example.com X-API-Token:123 name=John
, HTTP requests can be constructed with expressions close to natural language. JSON support is built-in by default, automatically converting data specified in name=value
format to JSON objects. Authentication features cover a wide range from Basic authentication, Digest authentication, Bearer Token to OAuth 2.0, with automatic authentication loading from .netrc
files. Session functionality allows persistence of authentication information and headers, providing efficiency for continuous API testing. Output features beautiful color display and formatting capabilities, making response verification easy. Plugin system enables feature extension, suitable for use in CI/CD pipelines and scripts.
Advantages & Disadvantages
Advantages
- Human-friendly: Intuitive syntax close to natural language
- Standard JSON Support: Automatic JSON conversion and beautiful output
- Rich Authentication: Support for Basic, Digest, Bearer, OAuth 2.0
- Session Management: Persistence of authentication information and headers
- Beautiful Output: Color display and readable formatting
- Extensibility: Feature extension through plugin system
- Cross-platform: Available on Windows, macOS, Linux
- Open Source: Free to use with active community
Disadvantages
- No GUI: Command-line only, no GUI provided
- Learning Curve: Challenge for those unfamiliar with command-line operations
- Binary Limitations: Some restrictions in handling binary data
- Complex Operations: Feature limitations for very complex API testing
Reference Links
- HTTPie Official Site
- GitHub - httpie/cli
- HTTPie Documentation
- HTTPie Python Package
- HTTPie Desktop App
Usage Examples
Basic HTTP Requests
# Basic GET request
http GET httpie.io/hello
# Simple GET (http method can be omitted)
http httpie.io/hello
# POST request with JSON data
http POST pie.dev/post name=John [email protected] age:=30
# PUT request with custom headers
http PUT pie.dev/put X-API-Token:123 name=John active:=true
# DELETE request
http DELETE pie.dev/delete/123 Authorization:"Bearer token123"
JSON Data and Type Specification
# String data (default)
http POST pie.dev/post name=John department=engineering
# Numeric data (using :=)
http POST pie.dev/post name=John age:=30 salary:=50000
# Boolean values
http POST pie.dev/post name=John active:=true married:=false
# Arrays
http POST pie.dev/post name=John skills:='["JavaScript", "Python", "React"]'
# Objects
http POST pie.dev/post name=John address:='{"city": "Tokyo", "country": "Japan"}'
# Complex nested JSON
http POST pie.dev/post \
platform[name]=HTTPie \
platform[about][mission]='Make APIs simple and intuitive' \
platform[about][stars]:=54000 \
platform[apps][]=Terminal \
platform[apps][]=Desktop \
platform[apps][]=Web
Authentication Methods
# Basic authentication
http -a username:password pie.dev/basic-auth/username/password
# Password input prompt
http -a username pie.dev/basic-auth/username/password
# Digest authentication
http -A digest -a username:password pie.dev/digest-auth/username/password
# Bearer Token authentication
http -A bearer -a token123 pie.dev/bearer
# API key via custom header
http GET api.example.com X-API-Key:your-api-key-here
# Automatic authentication from .netrc file
# Auto-use authentication info set in ~/.netrc
http pie.dev/basic-auth/httpie/test
# Ignore .netrc file
http --ignore-netrc pie.dev/basic-auth/httpie/test
Headers and Query Parameters
# Custom header configuration
http pie.dev/headers \
User-Agent:MyApp/1.0 \
'Cookie:session=abc123;user=john' \
X-Custom-Header:value \
Accept:application/json
# Query parameters (using ==)
http GET api.github.com/search/repositories \
q==httpie \
per_page==5 \
sort==stars
# Path parameters
http GET api.example.com/users/123/posts page==2 limit==10
# Multiple parameters with same name
http GET api.example.com/search \
tag==python \
tag==api \
tag==cli
File Operations
# File upload (multipart/form-data)
http -f POST pie.dev/post \
file@/path/to/file.txt \
description="Upload test"
# Send JSON file as request body
http POST pie.dev/post < data.json
# Read header values from files
http POST pie.dev/post \
X-Token:@token.txt \
Content:@content.txt
# Save response to file
http GET api.example.com/data > response.json
# Send binary file
http POST pie.dev/upload \
Content-Type:image/png \
< image.png
Session Management
# Create new session
http --session=./api-session.json pie.dev/headers \
API-Token:123 \
User-Agent:MyApp/1.0
# Check session file
cat api-session.json
# Reuse existing session (authentication and headers auto-applied)
http --session=./api-session.json pie.dev/get
# Named session (managed per host)
http --session=user1 -a user1:password pie.dev/login
# Reuse named session
http --session=user1 pie.dev/profile
# Check session file location
ls -la ~/.config/httpie/sessions/pie.dev/
Advanced Features
# Offline mode (only build request, don't send)
http --offline --print=HhBb pie.dev/post name=John
# Streaming response
http --stream pie.dev/stream/10
# Proxy configuration
http --proxy=http:http://proxy.example.com:8080 example.org
# SOCKS5 proxy
http --proxy=http:socks5://user:pass@proxy:1080 example.org
# Skip SSL certificate verification
http --verify=no https://self-signed.example.com
# Custom CA certificate
http --verify=/path/to/ca-bundle.crt https://example.com
# Client certificate authentication
http --cert=client.pem --cert-key=client.key https://secure.example.com
# Custom output formatting
http --format-options json.sort_keys:false,json.indent:2 pie.dev/get
# Display specific output only (H=headers, B=body)
http --print=HB pie.dev/get
# Both JSON and cURL output
http --print=HhBb pie.dev/post name=John
Scripts and CI/CD Integration
#!/bin/bash
# API test script example
# Environment variable setup
export API_BASE="https://api.example.com"
export API_TOKEN="your-token-here"
# Login
LOGIN_RESPONSE=$(http POST $API_BASE/auth/login \
username=testuser \
password=testpass \
--print=b)
TOKEN=$(echo $LOGIN_RESPONSE | jq -r '.access_token')
# Authenticated API test
http GET $API_BASE/profile \
Authorization:"Bearer $TOKEN" \
--check-status \
--ignore-stdin
# Error handling
if [ $? -ne 0 ]; then
echo "API test failed"
exit 1
fi
echo "API test passed"
# GitHub Actions usage example
# - name: Test API
# run: |
# pip install httpie
# http GET ${{ secrets.API_URL }}/health \
# X-API-Key:${{ secrets.API_KEY }} \
# --check-status
Plugins and Extensions
# Install plugin
httpie cli plugins install httpie-plugin-name
# List installed plugins
httpie cli plugins list
# Uninstall plugin
httpie cli plugins uninstall httpie-plugin-name
# HTTPie configuration file location
echo ~/.config/httpie/config.json
# Default options configuration example
{
"default_options": [
"--style=fruity",
"--print=HhBb"
]
}