How to Format a Long cURL Command
Copy a request as cURL from your browser's dev tools and you get one enormous line. Formatting it across multiple lines makes it readable, reviewable, and easy to drop into a script or a README.
The readable multi-line form
A formatted curl command puts each option on its own line, joined with a backslash:
curl 'https://api.example.com/users' \
-X POST \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer xyz' \
-d '{"name":"Ada"}'
The trailing \ is a line continuation — the shell treats all those lines as one command. It runs exactly the same as the single-line version, just far easier to read and diff.
How quoting works
Quoting matters when values contain spaces or special characters:
- Single quotes (
'...') are safest — the shell treats everything inside literally, so a JSON body or a header with spaces stays intact. - Values without spaces or special characters — like
POSTor a simple URL — don't need quotes. - A URL with a query string (
?page=2&sort=asc) should be quoted, because&otherwise tells the shell to run the command in the background.
Watch the ampersand
That last point is the most common footgun: an unquoted & in a URL splits the command. Formatting a command and quoting the URL fixes it in one step.
Related
Part of The Complete Guide to HTTP. Testing an API? Look up the HTTP status code you get back, or parse the response headers.
Try it
Paste a curl command and get a clean, multi-line version instantly — everything runs in your browser, nothing uploaded.