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 bodycurl -X POST URLUse a specific HTTP methodcurl -i URLInclude the response headers in the outputcurl -I URLHeaders only — sends a HEAD requestcurl -s URLSilent — hide the progress metercurl -sS URLSilent but still show errorscurl -L URLFollow redirectscurl -f URLFail with a non-zero exit code on HTTP errorsSending 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 GETHeaders & 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 jarDownloading files
curl -O URLSave with the remote filenamecurl -o name.zip URLSave under a name you choosecurl -OJ URLUse the filename from Content-Dispositioncurl -C - -O URLResume an interrupted download--limit-rate 500kCap the transfer speed-o a.txt URL1 -o b.txt URL2Fetch several URLs in one commandDebugging & 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