Skip to content
CheckcraftDownload
Practical workflow

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.

Checkcraft ·

Get help with your first test →

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.

API call diagram: method and URL, headers, body, status and response body, logs and database

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

FlagWhat it doesExample
-X METHODRequest method-X DELETE
-HRequest header, repeatable-H "Accept: application/json"
-dRequest body, method becomes POST-d '{"qty":2}'
--jsonJSON body with the right headers, curl 7.82+--json '{"qty":2}'
-G --data-urlencodeEncoded query parameters-G --data-urlencode "q=monitor 24"
-uLogin and password, Basic auth-u user:password
-FForm with fields and files-F "file=@photo.png"
-iShow status and response headers with the body-i
-IHEAD request, headers only-I
-vVerbose: connection, TLS, headers-v
-o and -OSave the response to a file-o report.zip
-LFollow redirects-L
-sSNo progress meter, errors kept-sS
-fExit code 22 on HTTP 400 and above-f
-wPrint status code, timing and more-w "%{http_code}"
--connect-timeout, --max-timeConnection and total timeouts--max-time 30
-xProxy-x http://proxy:3128
-b and -cSend and save cookies-b "session=abc"
-kSkip certificate checks, diagnostics only-k
Layers of an API call check: status, headers, body, calculations, logs, database

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=42

In 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

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.

Next step

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 run

No sign-up or email needed, the archive is ready in a couple of minutes. See the edition limits.

References

curl man page

Start with the linked example and compare its result with your own test requirement.

Ask a person

Get help with your first test

Tell us what you want to test or where you got stuck. We can help you start Checkcraft, choose an example and understand your first run. You can ask before downloading.

The Telegram group is public: do not post passwords, tokens or confidential work data. A description of your task is enough to start.

You can also email us support@checkcraft.ru

No account required. We will reply by email. This is a support request, not a newsletter subscription.