brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: curl -X only changes the method name, not what curl does

Curl
~/tips/tip-curl-x-only-changes-word

curl -X DELETE https://api.example.com/items/42

Know when -X helps and when it quietly breaks a request.

-X looks like the way to pick a method, and for DELETE it is. For GET, HEAD and POST it usually is not, because curl already picks those from the other options you give it.

This is the case where -X belongs:

curl -X DELETE https://api.example.com/items/42
curl -X PATCH --json '{"qty":3}' https://api.example.com/items/42

The man page is clear that the option only replaces the word in the request line. It does not change how curl behaves. So -X HEAD sends the word HEAD but still waits for a body that never comes, and the command hangs until a timeout. Use -I for a real HEAD request. And -d already makes a request a POST, so -X POST -d ... only adds noise.

The trap I find worst is -X POST together with -L. Normally curl switches to GET when it follows a 301, 302 or 303 redirect, like browsers do. With -X the custom method sticks to every request in the chain, so the new location gets a POST it may not expect.

My rule of thumb: let -d, -F, -T and -I choose the method, and keep -X for verbs curl has no option of its own for, such as DELETE, PATCH or a WebDAV PROPFIND.

Further reading: curl man page, everything curl: request method

More Curl tips curl --trace-ascii – https://example.com/ Retry-After: 120 curl -fsS --fail-early \ url = "https://example.com/data/latest.json" curl -4 -s -o /dev/null -w '%{remote_ip} %{http_code}\n' https://example.com/ All Curl tips (71) All topics

Link