curl command cheat sheet: flags and examples for APIs
Checkcraft is a desktop app for checking APIs and logs without code, with a free edition. Download, no sign-up →
curl is a command-line program for HTTP requests, available on Linux, macOS and Windows 10 and 11. One command shows whether an API answers, what it returns and which headers arrive. Below is a table of the flags you need nine times out of ten, ready commands for each case and links to detailed guides.
How a curl command is built
A command is the word curl, flags and a URL. Flags go in any order; quote the URL because the shell treats ampersands and question marks specially. With no flags curl sends a GET and prints the response body.
Where to start checking an API
First a request with -i: you see the status code and headers. If there is no answer or it looks odd, the same request with -v shows the connection, TLS and what actually went to the server. In scripts add -sS to hide the progress meter but keep errors, and -f so an HTTP error ends the command with a non-zero code.

From a one-off command to a repeatable check
curl answers what the server returned right now. It does not check whether the answer is correct: amounts, statuses and fields must be compared separately. When the same request runs after every change, move it into a saved check with expectations.
Main curl flags
| Flag | What it does | Example |
|---|---|---|
| -X METHOD | Request method | -X DELETE |
| -H | Request header, repeatable | -H "Accept: application/json" |
| -d | Request body, method becomes POST | -d '{"qty":2}' |
| --json | JSON body with the right headers, curl 7.82+ | --json '{"qty":2}' |
| -G --data-urlencode | Encoded query parameters | -G --data-urlencode "q=monitor 24" |
| -u | Login and password, Basic auth | -u user:password |
| -F | Form with fields and files | -F "file=@photo.png" |
| -i | Show status and response headers with the body | -i |
| -I | HEAD request, headers only | -I |
| -v | Verbose: connection, TLS, headers | -v |
| -o and -O | Save the response to a file | -o report.zip |
| -L | Follow redirects | -L |
| -sS | No progress meter, errors kept | -sS |
| -f | Exit code 22 on HTTP 400 and above | -f |
| -w | Print status code, timing and more | -w "%{http_code}" |
| --connect-timeout, --max-time | Connection and total timeouts | --max-time 30 |
| -x | Proxy | -x http://proxy:3128 |
| -b and -c | Send and save cookies | -b "session=abc" |
| -k | Skip certificate checks, diagnostics only | -k |

Ready commands
# GET с параметрами
curl "https://api.example.com/v1/orders?status=new&limit=10"
# POST с JSON и токеном
curl -X POST https://api.example.com/v1/orders \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $TOKEN" \
-d '{"sku":"MON-24","qty":2}'
# PUT и DELETE
curl -X PUT https://api.example.com/v1/orders/5001 -H "Content-Type: application/json" -d '{"status":"SHIPPED"}'
curl -X DELETE https://api.example.com/v1/orders/5001
# код ответа и заголовки
curl -i https://api.example.com/v1/orders/5001
# только код ответа
curl -s -o /dev/null -w "%{http_code}\n" https://api.example.com/health
# загрузить файл формой
curl -F "file=@report.pdf" -F "comment=отчёт" https://api.example.com/v1/upload
# скачать файл, пройти редиректы, не сохранять страницу ошибки
curl -fL -o report.zip https://files.example.com/download?id=42In Windows PowerShell type curl.exe and avoid single quotes around JSON: see curl on Windows and PowerShell.
Checking a response in a script
#!/bin/sh
# проверка в скрипте: код ответа и поле из JSON (нужна утилита jq)
body=$(curl -sS -f --max-time 30 https://api.example.com/v1/orders/5001) || { echo "запрос не прошёл"; exit 1; }
status=$(echo "$body" | jq -r '.status')
[ "$status" = "PAID" ] || { echo "ожидали PAID, пришло $status"; exit 1; }
echo "ок"Such a script suits one or two checks. With dozens of checks and readable reports, saved rules work better: see HTTP response checks.
All guides in the curl section
- curl GET request: parameters, response headers and status code
- cURL examples: GET and POST requests with JSON on Linux, Windows and PowerShell
- Headers in curl: Content-Type application/json, Accept and multiple -H
- curl with authorization: Bearer token, Basic, API key and headers
- curl errors: codes 6, 7, 22, 28, 35, 60 and how to fix them
- curl on Windows and PowerShell: how to run it and why commands fail
- Download a file with curl: -o, -O, redirects and resume
- curl through a proxy: -x, environment variables, SOCKS and no_proxy
- PHP cURL: GET and POST requests with JSON, headers and error handling
- Webhook: what it is, how it works and how to test it
Frequently asked questions
What is curl?
A command-line program for HTTP requests, built into Linux, macOS and Windows 10 and 11.
How do I send a POST with curl?
curl -X POST URL -H "Content-Type: application/json" -d '{"key":"value"}', or --json on curl 7.82+.
How do I see headers and the status code?
-i shows status and headers with the body, -I headers only, -w "%{http_code}" just the code.
How do I pass a token?
-H "Authorization: Bearer token"; use -u for login and password.
Repeat this on your own API
Checkcraft is a desktop app that saves API response checks without code and shows what did not match. Start with a sample, then use your own sanitized data. Free runs on Windows and Linux with no time limit.
Download FreeDownload and first runNo sign-up or email needed, the archive is ready in a couple of minutes. See the edition limits.
References
Start with the linked example and compare its result with your own test requirement.