What is the Default HTTP Method for Curl?
When using the command-line tool curl to interact with
web servers, understanding how it transmits requests is crucial for
debugging and API development. This article explains the default HTTP
method that curl uses when no method is explicitly defined,
how certain command-line options can implicitly change this default, and
how to manually specify different HTTP methods for your requests.
The Default HTTP Method: GET
By default, if you run a basic curl command with only a
URL, it uses the GET HTTP method. The GET method is
used to retrieve data from a specified resource.
For example, running the following command sends a standard HTTP GET request to the target server:
curl https://api.github.comIn this scenario, curl connects to the server, requests
the resource using GET, and outputs the response body directly to your
terminal.
Implicit Changes to the Default Method
While GET is the absolute default for a bare command,
curl will automatically switch its HTTP method if you use
specific data-sending or formatting flags. You do not need to specify
the method explicitly for these changes to occur:
POST: If you use the
-dor--dataoption to send data in the request body,curlautomatically changes the HTTP method from GET to POST.curl -d "param1=value1" https://example.com/apiPOST (Multipart/form-data): Using the
-For--formoption to upload files or send form data also implicitly changes the method to POST.curl -F "profile_picture=@image.png" https://example.com/uploadHEAD: If you use the
-Ior--headoption to retrieve only the HTTP headers of a document,curlimplicitly changes the method to HEAD.curl -I https://example.com
How to Explicitly Specify an HTTP Method
If you need to use HTTP methods other than the defaults—such as PUT,
DELETE, PATCH, or OPTIONS—you must explicitly define them using the
-X or --request flag followed by the desired
HTTP verb.
Here are a few examples of how to explicitly set the HTTP method:
PUT Request:
curl -X PUT -d "status=active" https://example.com/api/user/1DELETE Request:
curl -X DELETE https://example.com/api/user/1PATCH Request:
curl -X PATCH -d "email=new@example.com" https://example.com/api/user/1
Using the -X flag overrides any implicit behavior,
ensuring that curl uses the exact HTTP method required by
your target API.