Redirected Input

The universal method for passing request data is through redirected stdin(standard input)—piping. Such data is buffered and then with no furtherprocessing used as the request body. There are multiple useful ways to usepiping:

Redirect from a file:

  1. $ http PUT example.com/person/1 X-API-Token:123 < person.json

Or the output of another program:

  1. $ grep '401 Unauthorized' /var/log/httpd/error_log | http POST example.org/intruders

You can use echo for simple data:

  1. $ echo '{"name": "John"}' | http PATCH example.com/person/1 X-API-Token:123

You can also use a Bash here string:

  1. $ http example.com/ <<<'{"name": "John"}'

You can even pipe web services together using HTTPie:

  1. $ http GET https://api.github.com/repos/jakubroztocil/httpie | http POST httpbin.org/post

You can use cat to enter multiline data on the terminal:

  1. $ cat | http POST example.com
  2. <paste>
  3. ^D
  1. $ cat | http POST example.com/todos Content-Type:text/plain
  2. - buy milk
  3. - call parents
  4. ^D

On OS X, you can send the contents of the clipboard with pbpaste:

  1. $ pbpaste | http PUT example.com

Passing data through stdin cannot be combined with data fields specifiedon the command line:

  1. $ echo 'data' | http POST example.org more=data # This is invalid

To prevent HTTPie from reading stdin data you can use the—ignore-stdin option.

Request data from a filename

An alternative to redirected stdin is specifying a filename (as@/path/to/file) whose content is used as if it came from stdin.

It has the advantage that the Content-Typeheader is automatically set to the appropriate value based on thefilename extension. For example, the following request sends theverbatim contents of that XML file with Content-Type: application/xml:

  1. $ http PUT httpbin.org/put @/data/file.xml