# HTTPie
Docs: https://httpie.io/docs/cli/usage
```
http PUT pie.dev/put X-API-Token:123 name=John
```
The commands to use it are: `http` and `https`
Basic syntax:
```
http [flags] [METHOD] URL [ITEM [ITEM]]
```
If we ommit the method, HTTPie guesses the method to use - GET for simple requests, if you send json data, it will use post.
## Sending data
### Query params
Using the double equals sign we can set the query parameters
```
http get pie.dev/get hello=="a"
```
### Request body
With the equals sign we can set the parameters that will be sent in the body. This way, the value will be always serialized as string.
```bash
http PUT pie.dev/put \
name=John \ # String (default)
age:=29 \ # Raw JSON — Number
married:=false \ # Raw JSON — Boolean
hobbies:='["http", "pies"]' \ # Raw JSON — Array
favorite:='{"tool": "HTTPie"}' \ # Raw JSON — Object
bookmarks:=@files/data.json \ # Embed JSON file
description=@files/text.txt # Embed text file
```
### Nested JSON
There is a way to post nexted json data, but it is a bit tedious.
```bash
http pie.dev/post \
platform[name]=HTTPie \
platform[about][mission]='Make APIs simple and intuitive' \
platform[about][homepage]=httpie.io \
platform[about][homepage]=httpie.io \
platform[about][stars]:=54000 \
platform[apps][]=Terminal \
platform[apps][]=Desktop \
platform[apps][]=Web \
platform[apps][]=Mobile
```
Output
```json
{
"platform": {
"name": "HTTPie",
"about": {
"mission": "Make APIs simple and intuitive",
"homepage": "httpie.io",
"stars": 54000
},
"apps": [
"Terminal",
"Desktop",
"Web",
"Mobile"
]
}
}
```
When we need to post complex json data, the simplest ways is to save them to a file and then redirect input.
```
http post pie.dev/post < myInput.json
```
## Request preview
```
http --offline pie.dev/post hello=offline
```
Using the offline flag we can preview the request (eg. to ensure we are sending correct data)
## HTTP headers
To set custom headers you can use the `Header:Value` notation
```
http pie.dev/headers User-Agent:Bacon/1.0
```
## Authorization
Bearer auth
```
https -A bearer -a token pie.dev/bearer
```
All available auth modes are explained in the docs: https://httpie.io/docs/cli/authentication