Cheat sheets /

curl cheat sheet

Hit an API with a token, post some JSON, upload a file, or find out exactly where a slow request spends its time.

Download all 23 for Snippet Keeper Get Snippet Keeper

In Snippet Keeper, click Import at the bottom of the sidebar and choose the file. They land in your curl app, and ones you already have are skipped. The highlighted parts become fill-in fields: type a value (or pick one), and the finished command is on your clipboard.

Requests

GET, showing response headers

curl -i url

Headers only

curl -I url

Follow redirects

curl -L url

POST JSON

curl -X POST url \
  -H "Content-Type: application/json" \
  -d 'json'

POST JSON from a file

curl -X POST url -H "Content-Type: application/json" --data @file

PUT, PATCH or DELETE

curl -X method url

Send form fields

curl -d "field=value" url

Upload a file

curl -F "file=@file" url

Pretty-print a JSON response

curl -s url | jq

Auth

Bearer token

curl url -H "Authorization: Bearer token"

Basic auth

Asks for the password, so it isn’t left in your shell history.

curl -u user url

Keep cookies between requests

curl -c cookies.txt -b cookies.txt url

Downloads

Download to a file

curl -L -o file url

Download, keeping the remote name

curl -LO url

Resume a download

curl -L -C - -O url

Debugging

Show everything sent and received

curl -v url

Just the status code

curl -o /dev/null -s -w '%{http_code}\n' url

Where a request spends its time

curl -o /dev/null -s -w 'dns %{time_namelookup}s  connect %{time_connect}s  tls %{time_appconnect}s  first byte %{time_starttransfer}s  total %{time_total}s\n' url

Send a request to a specific IP

Test a new server before DNS points at it.

curl --resolve host:port:ip https://host/

Ignore certificate errors

Only for testing.

curl -k url

Give up after a few seconds

curl --max-time seconds url

Retry on failure

curl --retry count url

Go through a proxy

curl -x proxy url

Keep these one keystroke away.

Snippet Keeper is a Mac app for the commands you keep looking up. Press ⌥⇧Space in any app, type a few letters, fill in the blanks, and it’s on your clipboard.

Snippet Keeper asking for the values in a kubectl command before copying it