← 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

curl in practice

Seeing what really happens

curl -i shows response headers with the body, and curl -v shows the full conversation: DNS resolution, TLS handshake, request headers sent and response headers received. Adding -L follows redirects, which curl does not do by default — a frequent reason for unexpected empty responses or 301 status codes. -w "%{http_code} %{time_total}\n" -o /dev/null -s prints just the status code and total time, useful in scripts and quick performance checks.

Sending JSON correctly

-d sends data with a form content type by default, so APIs expecting JSON may reject it. Either add -H "Content-Type: application/json" or use --json '{"name":"Ada"}' in curl 7.82 and later, which also sets the Accept header. Quote JSON with single quotes on macOS and Linux shells; in Windows PowerShell, quoting rules differ, and writing the body to a file and sending it with -d @body.json avoids most escaping headaches.

Authentication

Bearer tokens go in a header: -H "Authorization: Bearer $TOKEN", reading the token from an environment variable instead of pasting it into the command, where it would be saved in shell history. Basic authentication uses -u user:password, or -u user to be prompted for the password. Cookies can be saved and reused with -c cookies.txt and -b cookies.txt when testing session-based logins.

Downloads and uploads

-O saves using the remote file name and -o name chooses one; -C - resumes an interrupted download. -F "[email protected]" uploads a file as multipart form data, as a browser form would. --fail makes curl exit with an error on HTTP errors, which matters in scripts — without it, a 404 page is happily saved as if it were the file you wanted.

Safety notes

-k disables certificate verification. It can help diagnose a local test server but must never be left in scripts that talk to real services. Be cautious with commands that pipe downloads straight into a shell, such as curl … | sh: read the script first. And remember that commands copied from browser developer tools contain your cookies and tokens — remove them before sharing.

Related guides

More cheat sheets