cURL Cheatsheet

HTTP from the command line.

1 credit

Basics

5 items
GET
curl https://api.example.com/users
Verbose
curl -v https://... (-vv for more)
Follow redirects
curl -L https://...
Silent + fail on error
curl -sSfL https://...
Output to file
curl -o out.html URL / -O (uses remote name)

Methods & body

5 items
POST JSON
curl -X POST -H "Content-Type: application/json" -d '{"k":1}' URL
POST from file
curl -X POST --data-binary @body.json URL
Form-encoded
curl -X POST -d "a=1&b=2" URL
Multipart upload
curl -F "file=@./photo.jpg" -F "desc=cat" URL
PUT / PATCH / DELETE
curl -X PATCH -d '{"x":1}' URL

Headers & auth

4 items
Add header
-H "Authorization: Bearer $TOKEN"
Basic auth
-u user:pass
Cookie
-b cookies.txt -c cookies.txt
User-Agent
-A "MyBot/1.0"

Timing & retry

4 items
Timing breakdown
curl -w "@curl-format.txt" -o /dev/null -s URL
Retry
--retry 5 --retry-delay 2 --retry-max-time 30
Timeout
--max-time 10 --connect-timeout 5
Show headers only
curl -I URL (HEAD)

Further reading