http
Send HTTP requests from the command line
TLDR
Make a simple GET request (shows response headers and content)
Print specific parts of the content (H: request headers, B: request body, h: response headers, b: response body, m: response metadata)
Specify the HTTP method when sending a request and use a proxy to intercept the request
Follow any 3xx redirects and specify additional headers in a request
Authenticate to a server using different authentication methods
Construct a request but do not send it (similar to a dry-run)
Use named sessions for persistent custom headers, auth credentials and cookies
Upload a file to a form (the example below assumes that the form field is )
SYNOPSIS
http [flags] [METHOD] URL [ITEM [ITEM ...]]
METHOD: Optional. The HTTP method (e.g., GET, POST, PUT, DELETE). If omitted, GET is the default unless request data is provided, in which case POST is inferred.
URL: The target URL for the request.
ITEM: Represents request data, headers, or files, defined as follows:
- KEY=VALUE: Request data (form-encoded, e.g., username=john)
- KEY:=VALUE: JSON request data (e.g., user:='{"id":1}')
- KEY:=@FILE: JSON field from file content (e.g., data:=@data.json)
- KEY=@FILE: File upload for a field (e.g., image=@pic.jpg)
- @FILE: Request body from a file (e.g., @request.json)
- HEADER:VALUE: Request header (e.g., Authorization:Bearer TOKEN)
PARAMETERS
-v, --verbose
Print the whole request and response, including headers and body.
-h, --help
Show a help message and exit.
-p, --print
Specify what parts of the request/response to print. Use a combination of 'H' (request headers), 'B' (request body), 'h' (response headers), 'b' (response body). Default is 'hb'.
-o, --output FILE
Save output to a file instead of printing to stdout.
-d, --download
Download the response body to a file. Implies --output, with the filename derived from the URL or Content-Disposition header.
-a, --auth USER:PASS
Specify HTTP authentication credentials (e.g., 'user:password').
--auth-type TYPE
Specify the authentication type. Common types are 'basic' (default) and 'digest'.
-j, --json
Serialize data items as a JSON object (this is the default behavior if not specified).
-f, --form
Serialize data items as a form-encoded string (application/x-www-form-urlencoded).
-x, --proxy PROTOCOL:HOST
Specify a proxy server (e.g., 'http:localhost:8080').
--verify
Verify SSL certificates. Can be 'yes' (default), 'no', or a path to a CA bundle file.
--timeout SECONDS
Set a timeout for the request in seconds.
-F, --follow
Follow redirects.
DESCRIPTION
HTTPie (pronounced "aitch-tee-tee-pie") is a user-friendly command-line HTTP client. It aims to make CLI interaction with web services as human-friendly as possible, focusing on intuitive syntax, readable output, and convenience.
Designed for testing, debugging, and general interaction with HTTP servers, it simplifies common tasks such as making requests, inspecting responses, and handling data formats like JSON.
Key features include:
- Expressive syntax: Requests are built with natural-looking key-value pairs for data and headers.
- JSON by default: Automatically infers JSON for request bodies and prettifies JSON responses, making API interaction seamless.
- Colorized output: Responses are syntax-highlighted for better readability.
- Built-in authentication: Supports various authentication schemes like Basic, Digest, and OAuth.
- File uploads and downloads: Easily handles file transfers.
- Proxy support: Configurable proxy settings.
CAVEATS
- Python Dependency: HTTPie is written in Python and requires a Python environment to be installed on the system.
- Not Pre-installed: Unlike curl or wget, HTTPie is generally not pre-installed on most Linux distributions and needs to be installed separately, typically via pip or a package manager.
- Performance: For extremely simple or repetitive requests, curl (being a C application) might offer marginally better performance due to lower overhead compared to HTTPie's Python-based execution.
JSON BY DEFAULT
Unlike many other HTTP clients, HTTPie treats request data without explicit type indicators as JSON by default. This significantly streamlines interaction with JSON-based APIs, as users simply provide key-value pairs (e.g., key=value), and HTTPie automatically handles the JSON serialization. Response bodies that are JSON are also automatically pretty-printed and syntax-highlighted, greatly enhancing readability.
READABLE OUTPUT
HTTPie prides itself on presenting HTTP responses in a clear, human-readable format. It automatically syntax-highlights headers and body content, especially JSON, making it easy to parse complex responses at a glance. This focus on aesthetic and functional output reduces the cognitive load during API development and debugging, making it a favorite for debugging and quick API tests.
HISTORY
HTTPie was created by Jakub Roztocil and first released in 2012. Its development was motivated by a desire for a more intuitive and developer-friendly command-line HTTP client compared to existing tools like curl, which, while powerful, could be seen as having a steeper learning curve for modern web API interactions.
It quickly gained popularity for its focus on sensible defaults (like JSON support), expressive syntax, and readable, colorized output, making it an excellent tool for testing, debugging, and interacting with RESTful APIs. Its design principles prioritize human-friendliness, leading to widespread adoption within the developer community.