Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CURL Command Line URL Parameters

Tags:

http

curl

People also ask

How do you add parameters in curl?

To make a PUT request with Curl, you need to use the -X PUT command-line option. PUT request data is passed with the -d parameter. If you give -d and omit -X, Curl will automatically choose the HTTP POST method. The -X PUT option explicitly tells Curl to select the HTTP PUT method instead of POST.

What is parameter in curl command?

The parameter {id} refers to the ID of a job. To use the GET method of this resource, you must substitute the ID of a job in the URL. For example, if the initiative ID is 31 , you might run the following command: curl -k -u jsmith:passw0rd https://ubuild.example.org:8080/jobs/31/ -X GET -H "Accept: application/json"

How do you pass multiple query parameters in curl command?

Windows user running curl binaries should use double-quotes instead of single quotes to get multiple query parameters command working.

How do I create a curl URL?

To make a GET request using Curl, run the curl command followed by the target URL. Curl automatically selects the HTTP GET request method unless you use the -X, --request, or -d command-line option. In this Curl GET example, we send Curl requests to the ReqBin echo URL.


The application/x-www-form-urlencoded Content-type header is not required (well, kinda depends). Unless the request handler expects parameters coming from the form body. Try it out:

curl -X DELETE "http://localhost:5000/locations?id=3"

or

curl -X GET "http://localhost:5000/locations?id=3"

Felipsmartins is correct.

It is worth mentioning that it is because you cannot really use the -d/--data option if this is not a POST request. But this is still possible if you use the -G option.

Which means you can do this:

curl -X DELETE -G 'http://localhost:5000/locations' -d 'id=3'

Here it is a bit silly but when you are on the command line and you have a lot of parameters, it is a lot tidier.

I am saying this because cURL commands are usually quite long, so it is worth making it on more than one line escaping the line breaks.

curl -X DELETE -G \
'http://localhost:5000/locations' \
-d id=3 \
-d name=Mario \
-d surname=Bros

This is obviously a lot more comfortable if you use zsh. I mean when you need to re-edit the previous command because zsh lets you go line by line. (just saying)

Hope it helps.