1
0
mirror of https://github.com/httpie/cli.git synced 2024-11-24 08:22:22 +02:00
httpie-cli/README.md

114 lines
5.1 KiB
Markdown
Raw Normal View History

2012-02-25 15:39:38 +03:00
## HTTPie: cURL for humans
2012-03-04 13:54:27 +03:00
[![Build Status](https://secure.travis-ci.org/jkbr/httpie.png)](http://travis-ci.org/jkbr/httpie)
2012-03-04 01:09:13 +03:00
HTTPie is a CLI frontend for [python-requests](http://python-requests.org) built out of frustration. It provides an `http` command that can be used to easily issue HTTP requests. It is meant to be used by humans to interact with HTTP-based APIs and web servers. The response headers are colorized and the body is syntax-highlighted if its `Content-Type` is known to [Pygments](http://pygments.org/) (unless the output is redirected).
2012-02-25 15:39:38 +03:00
2012-02-25 16:42:06 +03:00
![httpie](https://github.com/jkbr/httpie/raw/master/httpie.png)
2012-02-25 15:39:38 +03:00
### Installation
Latest stable version using [pip](http://www.pip-installer.org/en/latest/index.html):
pip install -U httpie
# easy_install httpie
Master:
pip install -U https://github.com/jkbr/httpie/tarball/master
2012-02-25 15:39:38 +03:00
2012-02-25 15:47:23 +03:00
### Usage
2012-02-25 15:39:38 +03:00
2012-02-27 13:54:41 +03:00
http [flags] METHOD URL [header:value | data-field-name=value]*
2012-02-25 15:47:23 +03:00
2012-02-25 22:37:33 +03:00
The default request `Content-Type` is `application/json` and data fields are automatically serialized as a JSON `Object`, so this:
2012-02-25 15:47:23 +03:00
2012-02-27 13:54:41 +03:00
http PATCH api.example.com/person/1 X-API-Token:123 name=John email=john@example.org
2012-02-25 15:47:23 +03:00
2012-02-25 15:49:50 +03:00
Will issue the following request:
2012-02-25 15:47:23 +03:00
PATCH /person/1 HTTP/1.1
User-Agent: HTTPie/0.1
X-API-Token: 123
Content-Type: application/json; charset=utf-8
2012-02-27 13:54:41 +03:00
{"name": "John", "email": "john@example.org"}
2012-03-04 12:50:23 +03:00
You can pass other types than just strings using the `field:=value` notation. It allows you to set arbitrary JSON to the data fields:
http PUT httpie.org/pies bool:=true list:=[1,2,3] 'object:={"a": "b", "c": "d"}'
Produces the following JSON request:
2012-03-04 04:48:31 +03:00
{"bool": true, "list": [1, 2, 3], "object": {"a": "b", "c": "d"}}
2012-02-25 15:49:50 +03:00
You can use the `--form` flag to set `Content-Type` and serialize the data as `application/x-www-form-urlencoded`.
2012-02-25 15:39:38 +03:00
2012-02-25 15:47:23 +03:00
The data to be sent can also be passed via `stdin`:
2012-02-27 13:54:41 +03:00
http PUT api.example.com/person/1 X-API-Token:123 < person.json
Most of the flags mirror the arguments you would use with `requests.request`. See `http -h`:
2012-03-04 13:22:09 +03:00
usage: http [-h] [--version] [--json | --form] [--traceback]
[--pretty | --ugly] [--headers | --body] [--style STYLE]
[--auth AUTH] [--verify VERIFY] [--proxy PROXY]
[--allow-redirects] [--file PATH] [--timeout TIMEOUT]
METHOD URL [items [items ...]]
2012-03-04 04:48:31 +03:00
HTTPie - cURL for humans.
positional arguments:
2012-03-04 13:22:09 +03:00
METHOD HTTP method to be used for the request (GET, POST,
2012-03-04 04:48:31 +03:00
PUT, DELETE, PATCH, ...).
URL Protocol defaults to http:// if the URL does not
include it.
2012-03-04 13:22:09 +03:00
items HTTP header (key:value), data field (key=value) or raw
JSON field (field:=value).
2012-03-04 04:48:31 +03:00
optional arguments:
-h, --help show this help message and exit
2012-03-04 13:22:09 +03:00
--version show program's version number and exit
2012-03-04 04:48:31 +03:00
--json, -j Serialize data items as a JSON object and set Content-
Type to application/json, if not specified.
--form, -f Serialize data items as form values and set Content-
Type to application/x-www-form-urlencoded, if not
specified.
2012-03-04 13:22:09 +03:00
--traceback Print exception traceback should one occur.
--pretty, -p If stdout is a terminal, the response is prettified by
default (colorized and indented if it is JSON). This
flag ensures prettifying even when stdout is
redirected.
2012-03-04 04:48:31 +03:00
--ugly, -u Do not prettify the response.
--headers, -t Print only the response headers.
--body, -b Print only the response body.
--style STYLE, -s STYLE
Output coloring style, one of autumn, borland, bw,
colorful, default, emacs, friendly, fruity, manni,
monokai, murphy, native, pastie, perldoc, solarized,
tango, trac, vim, vs. Defaults to solarized.
--auth AUTH, -a AUTH username:password
--verify VERIFY Set to "yes" to check the host's SSL certificate. You
can also pass the path to a CA_BUNDLE file for private
certs. You can also set the REQUESTS_CA_BUNDLE
environment variable.
--proxy PROXY String mapping protocol to the URL of the proxy (e.g.
http:foo.bar:3128).
--allow-redirects Set this flag if full redirects are allowed (e.g. re-
POST-ing of data at new ``Location``)
--file PATH File to multipart upload
--timeout TIMEOUT Float describes the timeout of the request (Use
socket.setdefaulttimeout() as fallback).
2012-03-04 15:33:18 +03:00
### Contributors
[View contributors on GitHub](https://github.com/jkbr/httpie/contributors).
2012-03-04 15:33:18 +03:00
### Changelog
2012-03-04 15:46:41 +03:00
* [0.1.6](https://github.com/jkbr/httpie/compare/0.1.4...0.1.6) (2012-03-04)