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

curl Command Builder

Pick a method, add headers and a body, and get a curl command that fails loudly on errors instead of silently saving an HTML error page.

Make curl fail on HTTP errors

By default curl treats a 404 or 500 as success: it prints the error page and exits 0, so scripts carry on as if everything worked. Add --fail-with-body (or -f) so an HTTP error gives a non-zero exit code, -sS to hide the progress bar but keep real errors, and -L to follow redirects. Keep secrets out of the command itself: reference a token from an environment variable so it does not land in your shell history, and remember that anything on the command line is visible to other users in ps.

Build curl commands for APIs and downloads

This curl builder assembles requests with the right flags for each job: -X for the method, -H for headers, --data or --json for request bodies, -F for multipart file uploads, -u for basic authentication, and an Authorization header for bearer tokens. It adds the reliability options scripts need, like --fail-with-body, --retry with --retry-all-errors, connection and total timeouts, and -o or -O to save output, and it quotes everything safely for the shell.

curl FAQ

What is the difference between --data and --json?

--data sends the body as application/x-www-form-urlencoded unless you set a Content-Type header yourself. --json, added in curl 7.82, sends the body and sets both Content-Type and Accept to application/json in one flag. On older curl, use -H 'Content-Type: application/json' with --data.

Should I use -k to fix certificate errors?

Only against a server you control, while testing. -k disables certificate verification entirely, so a man-in-the-middle could read and alter the traffic. For a self-signed certificate, pass it with --cacert cert.pem instead.

curl or wget?

wget is built for downloading files and mirroring sites, with recursion and resume built in. curl is built for talking to URLs: any method, any header, dozens of protocols, and a library behind it. For APIs, curl; for pulling down a directory tree, wget.

How do I see exactly what curl sends?

Add -v to print request and response headers, or --trace-ascii trace.txt for the full exchange including the body. Both redact nothing, so be careful sharing the output if it contains tokens.