OSDN Git Service

Regular updates
[twpd/master.git] / httpie.md
1 ---
2 title: httpie
3 category: CLI
4 layout: 2017/sheet
5 weight: -3
6 updated: 2017-09-04
7 description: |
8   $ http POST http://example.com name="John" Host:example.com — JSON, cookies, files, auth, and other httpie examples.
9 intro: |
10   [HTTPie](https://httpie.org/) is a command-line HTTP client.
11 ---
12
13 ### Parameters
14
15 ```bash
16 $ http POST http://example.com/posts/3 \
17     Origin:example.com \  # :   HTTP headers
18     name="John Doe" \     # =   string
19     q=="search" \         # ==  URL parameters (?q=search)
20     age:=29 \             # :=  for non-strings
21     list:='[1,3,4]' \     # :=  json
22     file@file.bin \       # @   attach file
23     token=@token.txt \    # =@  read from file (text)
24     user:=@user.json      # :=@ read from file (json)
25 ```
26
27 ### Forms
28
29 ```bash
30 $ http --form POST example.com \
31     name="John Smith" \
32     cv=@document.txt
33 ```
34
35 ### Options
36
37 Print options:
38 {: .-setup}
39
40 ```bash
41 -v, --verbose            # same as --print=HhBb --all
42 -h, --headers            # same as --print=h
43 -b, --body               # same as --print=b
44     --all                # print intermediate requests
45     --print=HhBb         # H: request headers
46                          # B: request body
47                          # h: response headers
48                          # b: response body
49     --pretty=none        # all | colors | format
50     --json | -j          # Response is serialized as a JSON object.
51 ```
52
53 #### Authentication
54
55 ```bash
56     --session NAME
57 -a, --auth USER:PASS
58     --auth-type basic
59     --auth-type digest
60 ```
61
62 #### Session
63
64 ```bash
65     --session NAME       # store auth and cookies
66     --session-read-only NAME
67 ```
68
69 #### Downloading
70
71 ```bash
72 -d, --download           # like wget
73 -c, --continue
74 -o, --output FILE
75 ```
76
77 #### Others
78
79 ```bash
80 -F, --follow             # follow redirects
81     --max-redirects N    # maximum for --follow
82     --timeout SECONDS
83     --verify no          # skip SSL verification
84     --proxy http:http://foo.bar:3128
85 ```
86
87 ### References
88
89 * <https://github.com/jakubroztocil/httpie>