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, -h | Only the response headers are printed. |
—body, -b | Only the response body is printed. |
—verbose, -v | Print the whole HTTP exchange (request and response).This option also enables —all (see below). |
—print, -p | Selects parts of the HTTP exchange. |
—verbose
can often be useful for debugging the request and generatingdocumentation examples:
- $ http --verbose PUT httpbin.org/put hello=world
- PUT /put HTTP/1.1
- Accept: application/json, */*
- Accept-Encoding: gzip, deflate
- Content-Type: application/json
- Host: httpbin.org
- User-Agent: HTTPie/0.2.7dev
- {
- "hello": "world"
- }
- HTTP/1.1 200 OK
- Connection: keep-alive
- Content-Length: 477
- Content-Type: application/json
- Date: Sun, 05 Aug 2012 00:25:23 GMT
- Server: gunicorn/0.13.4
- {
- […]
- }
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:
Character | Stands for |
---|---|
H | request headers |
B | request body |
h | response headers |
b | response body |
Print request and response headers:
- $ 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 —all
option. The intermediary HTTP communication include followed redirects(with —follow
), the first unauthorized request when HTTP digestauthentication is used (—auth=digest
), etc.
- # Include all responses that lead to the final one:
- $ 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.
- # Print the intermediary requests/responses differently than the final one:
- $ 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 HEAD
request, 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:
- $ 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