cheatsheets/httpie.md

101 lines
2.2 KiB
Markdown
Raw Permalink Normal View History

2014-06-14 02:26:51 +00:00
---
title: httpie
2015-11-24 05:06:06 +00:00
category: CLI
2017-09-04 01:33:44 +00:00
weight: -3
2020-07-05 11:11:36 +00:00
updated: 2020-07-05
2017-10-14 18:53:08 +00:00
description: |
$ http POST http://example.com name="John" Host:example.com — JSON, cookies, files, auth, and other httpie examples.
2014-06-14 02:26:51 +00:00
---
2021-01-07 04:26:30 +00:00
### Introduction
2020-07-05 14:38:31 +00:00
{: .-intro}
[HTTPie](https://httpie.org/) is a command-line HTTP client.
- [HTTPie website](https://httpie.org/) _(httpie.org)_
- [HTTPie documentation](https://httpie.org/docs) _(httpie.org)_
- [Try it online](https://httpie.org/run) _(httpie.org)_
2017-09-04 01:33:44 +00:00
### Parameters
```bash
2017-09-04 02:38:46 +00:00
$ http POST http://example.com/posts/3 \
2017-09-04 01:34:27 +00:00
Origin:example.com \ # : HTTP headers
name="John Doe" \ # = string
q=="search" \ # == URL parameters (?q=search)
age:=29 \ # := for non-strings
2017-09-04 02:31:20 +00:00
list:='[1,3,4]' \ # := json
2017-09-04 01:34:27 +00:00
file@file.bin \ # @ attach file
token=@token.txt \ # =@ read from file (text)
user:=@user.json # :=@ read from file (json)
2017-09-04 01:33:44 +00:00
```
2014-06-14 02:26:51 +00:00
### Forms
2017-09-04 01:33:44 +00:00
```bash
$ http --form POST example.com \
name="John Smith" \
cv=@document.txt
```
2014-06-14 02:26:51 +00:00
### Raw JSON
```bash
$ echo '{"hello": "world"}' | http POST example.com/post
```
2014-06-14 05:44:18 +00:00
### Options
2020-07-05 15:35:26 +00:00
#### Printing options
2014-06-14 05:44:18 +00:00
2017-09-04 01:33:44 +00:00
```bash
2017-09-04 02:38:46 +00:00
-v, --verbose # same as --print=HhBb --all
-h, --headers # same as --print=h
-b, --body # same as --print=b
--all # print intermediate requests
2017-09-04 01:33:44 +00:00
--print=HhBb # H: request headers
# B: request body
# h: response headers
# b: response body
--pretty=none # all | colors | format
2018-11-16 19:52:30 +00:00
--json | -j # Response is serialized as a JSON object.
2017-09-04 01:33:44 +00:00
```
2014-06-14 05:44:18 +00:00
2018-05-15 23:55:00 +00:00
#### Authentication
2016-01-17 16:05:50 +00:00
2017-09-04 01:33:44 +00:00
```bash
--session NAME
-a, --auth USER:PASS
--auth-type basic
--auth-type digest
```
2014-06-14 05:44:18 +00:00
2018-05-15 23:55:00 +00:00
#### Session
2017-09-04 02:38:46 +00:00
```bash
--session NAME # store auth and cookies
--session-read-only NAME
```
2018-05-15 23:55:00 +00:00
#### Downloading
2014-06-14 05:44:18 +00:00
2017-09-04 01:33:44 +00:00
```bash
2017-09-04 02:38:46 +00:00
-d, --download # like wget
-c, --continue
2017-09-04 01:33:44 +00:00
-o, --output FILE
```
2014-06-14 05:44:18 +00:00
2018-05-15 23:55:00 +00:00
#### Others
2014-06-14 05:44:18 +00:00
2017-09-04 01:33:44 +00:00
```bash
2017-09-04 02:38:46 +00:00
-F, --follow # follow redirects
--max-redirects N # maximum for --follow
2017-09-04 01:33:44 +00:00
--timeout SECONDS
--verify no # skip SSL verification
2014-06-14 05:44:18 +00:00
--proxy http:http://foo.bar:3128
2017-09-04 01:33:44 +00:00
```
2014-06-14 05:44:18 +00:00
2014-06-14 02:26:51 +00:00
### References
2017-09-04 01:33:44 +00:00
* <https://github.com/jakubroztocil/httpie>