Skip to content
Latchkey

curl -X / --request: Set the HTTP Method

curl -X overrides the method, but adding -d already implies POST.

Most REST calls need an explicit method. Knowing when curl sets it for you avoids redundant or surprising requests.

What it does

-X / --request sets the HTTP method used for the request. curl defaults to GET, and switches to POST automatically when you pass -d / --data or --json. -X only changes the method string; it does not add a body. Use it for PUT, PATCH, and DELETE, or to force a method that curl would not otherwise choose.

Common usage

Terminal
curl -X DELETE https://api.example.com/runners/42
curl -X PUT -d @body.json https://api.example.com/config
curl -X PATCH -H 'Content-Type: application/json' -d '{"state":"off"}' https://api.example.com/x
# -d already implies POST, so -X POST is redundant here:
curl -d 'a=1' https://api.example.com/x

Flags

FlagWhat it does
-X / --request <M>Set the method (GET, POST, PUT, PATCH, DELETE, ...)
-d / --dataSend a body; implies POST unless -X overrides
--json <data>Send a body and set JSON headers; implies POST (curl 7.82+)
-G / --getSend -d data as a query string with GET

In CI

A subtle trap: -X GET combined with -d still sends the body and can confuse servers or proxies. If you want data on a GET, use -G so curl appends it to the URL. Do not set -X POST just because you added -d; -d already implies POST.

Common errors in CI

curl: (18) transfer closed with outstanding read data remaining can appear when a server rejects an unexpected method. A 405 Method Not Allowed in the body means the endpoint does not accept that method; check the API docs and correct -X.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →