Cheatsheet: curl

Last updated 2026-06-21

Requests and methods

Send a GET request to a URL.

curl "https://testapi.devtoolsdaily.com/users?limit=5"

Send a POST request with form-encoded data.

curl --data "firstName=John" "https://testapi.devtoolsdaily.com/users/1"

Send a POST request with a JSON body.

curl -H "Content-Type: application/json" -X POST -d '{"firstName":"John"}'   "https://testapi.devtoolsdaily.com/users/1"

Send a PUT request with data.

curl -X PUT --data "firstName=John" "https://testapi.devtoolsdaily.com/users/1"

Send a DELETE request.

curl -X DELETE "https://testapi.devtoolsdaily.com/users/1"

Use a custom HTTP method such as PATCH.

curl -X PATCH -H "Content-Type: application/json" -d '{"active":true}' https://api.example.com/users/1

Headers and authentication

Send a request with a custom header.

curl -H "appKey: asdf123123" "https://testapi.devtoolsdaily.com/users/1"

Send a bearer token for OAuth-style API authentication.

curl -H "Authorization: Bearer ACCESS_TOKEN" https://api.example.com/me

Send a request with Basic Authentication.

curl -u username:password "https://testapi.devtoolsdaily.com/users/1"

Include response headers in the output.

curl -i https://testapi.devtoolsdaily.com

Send only a HEAD request to fetch headers.

curl -I https://example.com

Downloads and output

Save the response body to a specific file.

curl "https://testapi.devtoolsdaily.com/users?limit=5" -o filename.txt

Download a file using the remote filename from the URL.

curl -O https://example.com/archive.zip

Follow redirects while downloading or calling an endpoint.

curl -L https://testapi.devtoolsdaily.com

Resume an interrupted download.

curl -C - -O https://example.com/big-file.iso

Fail on HTTP errors and show the error body when available.

curl --fail-with-body https://api.example.com/items/404

Debugging and options

Show verbose connection details including request and response headers.

curl -v https://example.com

Print only the HTTP status code and discard the response body.

curl -s -o /dev/null -w "%{http_code}
" https://example.com

Set connection and overall request timeouts.

curl --connect-timeout 5 --max-time 20 https://api.example.com

Send cookies in a request.

curl -b "session=abc123; theme=dark" https://example.com/account

Save cookies from a response and reuse them later.

curl -c cookies.txt https://example.com/login
curl -b cookies.txt https://example.com/account

Submit multipart form data, including a file upload.

curl -F "name=avatar" -F "file=@avatar.png" https://api.example.com/upload

Upload raw file contents with PUT.

curl -T ./build.tar.gz https://uploads.example.com/build.tar.gz

Ignore TLS certificate validation for local testing only.

curl -k https://localhost:8443

See also: