LinuxCommandLibrary

httpie

Send HTTP requests

TLDR

Check updates for http

$ httpie cli check-updates
copy

List installed http plugins
$ httpie cli plugins list
copy

Install/upgrade/uninstall plugins
$ httpie cli plugins [install|upgrade|uninstall] [plugin_name]
copy

SYNOPSIS

http [flags] [METHOD] URL [REQUEST_ITEM...]

Example: http GET example.com/api/users id==1
Example: http POST example.com/api/posts title='My Post' body='Content'

PARAMETERS

URL
    The target URL to which the HTTP request will be sent. Can be just a hostname or a full URL with scheme, host, path, and query parameters.

METHOD
    The HTTP method (e.g., GET, POST, PUT, DELETE, PATCH, HEAD, OPTIONS). If omitted, GET is assumed unless data items are provided, in which case POST is assumed.

REQUEST_ITEM
    One or more request items that specify headers, data fields, JSON fields, or file uploads. See 'Additional' section for syntax details.

--json, -j
    Shorthand for Content-Type: application/json header and ensures outgoing data is serialized as JSON. This is the default if the method is POST/PUT and data items are provided.

--form, -f
    Shorthand for Content-Type: application/x-www-form-urlencoded for form submissions. Data items will be serialized as form fields.

--verbose, -v
    Print the entire request and response, including headers and body. Useful for debugging.

--headers, -h
    Print only the response headers. Useful for quickly inspecting metadata without downloading the body.

--body, -b
    Print only the response body. Useful for getting just the content without headers.

--check-status, -C
    Exit with an error code if the response status is 3xx (redirect), 4xx (client error), or 5xx (server error). Useful for scripting.

--auth USER:PASS, -a USER:PASS
    Provide credentials for HTTP Basic or Digest authentication. Example: --auth user:pass

--proxy PROTOCOL:PROXY_URL
    Use a proxy for requests. Example: --proxy http:http://localhost:8080

--download, -d
    Download the response body to a file. By default, the filename is derived from the URL or Content-Disposition header.

--output FILE, -o FILE
    Write the response body to the specified file instead of standard output.

--session SESSION_NAME, -s SESSION_NAME
    Create or reuse a session. Sessions store cookies and auth credentials for subsequent requests. Example: --session mysession

--print WHAT, -p WHAT
    Controls what parts of the HTTP exchange are printed to standard output. WHAT can be 'H' (request headers), 'B' (request body), 'h' (response headers), 'b' (response body), etc. Example: -p Hhb

--ignore-stdin
    Prevent reading data from standard input, even if stdin is not a TTY. Useful when piping to httpie but not intending to send stdin content.

DESCRIPTION

Httpie (pronounced 'aitch-tee-pie') is a command-line HTTP client that makes interacting with web services from the terminal as human-friendly as possible. It is designed for easy API testing, debugging, and general interaction with HTTP servers.

While curl is a powerful and ubiquitous tool, Httpie aims to provide a more intuitive syntax, colorful and formatted output (especially for JSON), and a focus on developer experience. It simplifies common tasks like sending JSON data, handling authentication, and managing sessions, often requiring fewer flags and a more natural command structure compared to its counterparts. Httpie automatically handles JSON input/output, offers various output options (like showing only headers or body), and supports persistent sessions, making it an excellent choice for modern web development workflows.

CAVEATS

While Httpie is user-friendly, it's not as universally pre-installed as curl on most Linux systems, meaning it might require a separate installation. For extremely low-level network debugging or very complex, obscure HTTP features, curl might offer more granular control.

REQUEST ITEM SYNTAX

Httpie uses a natural and flexible syntax for specifying request data, headers, and files:

  • KEY=VALUE: Text data field for application/x-www-form-urlencoded or JSON (default). For JSON, VALUE is interpreted as a string.
  • KEY:=VALUE: JSON data field where VALUE is interpreted as a raw JSON value (number, boolean, object, array, null).
  • KEY:VALUE: HTTP header. Example: Authorization:Bearer token
  • KEY=@FILE: File upload field. The content of FILE is read and sent as a file.
  • KEY:=@FILE: JSON data field whose value is taken from FILE, parsed as JSON.
  • KEY==VALUE: URL query string parameter. Example: id==1 becomes ?id=1.
  • --raw FILE: Send the content of FILE directly as the request body.

HTTP METHODS

Httpie automatically infers the HTTP method if not explicitly provided:

  • If no data items (REQUEST_ITEMs) are present, the method defaults to GET.
  • If data items are present, the method defaults to POST.

You can always specify the method explicitly before the URL, e.g., http PUT example.com/api/resource.

HISTORY

Httpie was created by Jakub Roztocil and first released in 2012. Its primary motivation was to provide a more intuitive and aesthetically pleasing command-line interface for interacting with HTTP services, addressing common frustrations users experienced with existing tools like curl when performing API testing and debugging. It quickly gained popularity within the developer community for its simplified syntax, automatic JSON handling, and colorful output, becoming a preferred alternative for many over time.

SEE ALSO

curl(1), wget(1), netcat(1)

Copied to clipboard