Output options

By default, HTTPie only outputs the final response and the whole responsemessage is printed (headers as well as the body). You can control what shouldbe printed via several options:

—headers, -hOnly the response headers are printed.
—body, -bOnly the response body is printed.
—verbose, -vPrint the whole HTTP exchange (request and response).This option also enables —all (see below).
—print, -pSelects parts of the HTTP exchange.

—verbose can often be useful for debugging the request and generatingdocumentation examples:

  1. $ http --verbose PUT httpbin.org/put hello=world
  2. PUT /put HTTP/1.1
  3. Accept: application/json, */*
  4. Accept-Encoding: gzip, deflate
  5. Content-Type: application/json
  6. Host: httpbin.org
  7. User-Agent: HTTPie/0.2.7dev
  8.  
  9. {
  10. "hello": "world"
  11. }
  12.  
  13.  
  14. HTTP/1.1 200 OK
  15. Connection: keep-alive
  16. Content-Length: 477
  17. Content-Type: application/json
  18. Date: Sun, 05 Aug 2012 00:25:23 GMT
  19. Server: gunicorn/0.13.4
  20.  
  21. {
  22. […]
  23. }

What parts of the HTTP exchange should be printed

All the other output options are under the hood just shortcuts forthe more powerful —print, -p. It accepts a string of characters eachof which represents a specific part of the HTTP exchange:

CharacterStands for
Hrequest headers
Brequest body
hresponse headers
bresponse body

Print request and response headers:

  1. $ http --print=Hh PUT httpbin.org/put hello=world

Viewing intermediary requests/responses

To see all the HTTP communication, i.e. the final request/response aswell as any possible intermediary requests/responses, use the —alloption. The intermediary HTTP communication include followed redirects(with —follow), the first unauthorized request when HTTP digestauthentication is used (—auth=digest), etc.

  1. # Include all responses that lead to the final one:
  2. $ http --all --follow httpbin.org/redirect/3

The intermediary requests/response are by default formatted according to—print, -p (and its shortcuts described above). If you'd like to changethat, use the —history-print, -P option. It takes the samearguments as —print, -p but applies to the intermediary requests only.

  1. # Print the intermediary requests/responses differently than the final one:
  2. $ http -A digest -a foo:bar --all -p Hh -P H httpbin.org/digest-auth/auth/foo/bar

Conditional body download

As an optimization, the response body is downloaded from the serveronly if it's part of the output. This is similar to performing a HEADrequest, except that it applies to any HTTP method you use.

Let's say that there is an API that returns the whole resource when it isupdated, but you are only interested in the response headers to see thestatus code after an update:

  1. $ http --headers PATCH example.org/Really-Huge-Resource name='New Name'

Since we are only printing the HTTP headers here, the connection to the serveris closed as soon as all the response headers have been received.Therefore, bandwidth and time isn't wasted downloading the bodywhich you don't care about. The response headers are downloaded always,even if they are not part of the output