elefcode
← All cheat sheets

Tools

curl Cheat Sheet — Common Commands and Flags

curl is the standard way to make HTTP requests from the terminal. This reference covers the flags you reach for when testing an API or downloading a file.

Put it into practice with the matching tool.

Look up a status code →

Advertisement

Basic requests

curl https://api.example.comGET a URL and print the body
curl -X POST URLUse a specific HTTP method
curl -i URLInclude the response headers in the output
curl -I URLHeaders only — sends a HEAD request
curl -s URLSilent — hide the progress meter
curl -sS URLSilent but still show errors
curl -L URLFollow redirects
curl -f URLFail with a non-zero exit code on HTTP errors

Sending data

-d '{"a":1}'Send a request body (implies POST)
-H "Content-Type: application/json"Required when sending JSON
-d @body.jsonRead the body from a file
-d "name=ada&role=dev"URL-encoded form data
--data-urlencode "q=a b&c"Encode a value that contains special characters
-F [email protected]Multipart upload — for file fields
-F "name=ada" -F [email protected]Mix fields and files in one form
-G -d "q=test"Send the data as a query string on a GET

Headers & authentication

-H "Accept: application/json"Add a request header — repeatable
-H "Authorization: Bearer TOKEN"Bearer token auth
-u user:passHTTP basic authentication
-u userPrompt for the password instead of typing it
-A "MyAgent/1.0"Set the User-Agent
-e https://example.comSet the Referer
-b "session=abc"Send cookies
-c cookies.txt -b cookies.txtSave and reuse a cookie jar

Downloading files

curl -O URLSave with the remote filename
curl -o name.zip URLSave under a name you choose
curl -OJ URLUse the filename from Content-Disposition
curl -C - -O URLResume an interrupted download
--limit-rate 500kCap the transfer speed
-o a.txt URL1 -o b.txt URL2Fetch several URLs in one command

Debugging & timing

-vVerbose — show the full request and response headers
--trace-ascii -Dump everything sent and received
-w "%{http_code}\n" -o /dev/null -sPrint only the status code
-w "%{time_total}\n"Print how long the request took
--max-time 10Give up after 10 seconds total
--connect-timeout 5Give up if the connection takes too long
--retry 3Retry on transient failures
-kSkip TLS certificate verification — development only
--resolve host:443:1.2.3.4Test a host against a specific IP
-x http://proxy:8080Route the request through a proxy

More cheat sheets