How do I test a RESTful PUT (or DELETE) method using cURL?
5 Answers
Using the majuscule -X
flag with whatever HTTP verb you want:
curl -X PUT -d argument=value -d argument2=value2 http://localhost:8080
This example also uses the -d
flag to provide arguments with your PUT request.

- 7,195
- 6
- 56
- 107

- 15,840
- 9
- 42
- 41
-
25"man curl" on -X: "Normally you don't need this option. All sorts of GET, HEAD, POST and PUT requests are rather invoked by using dedicated command line options." But I couldn't find another way. – Martin C. Martin Nov 26 '13 at 15:18
-
52A year later, I found a way! curl -T – Martin C. Martin Dec 04 '14 at 17:52
-
2As Martin C. Martin's answer also changes to GET after a redirect from the server this is the more useful answer in my opinion. – Martin Oct 02 '15 at 12:10
-
2To achieve the `GET` after a redirect, add the parameter `--location` – Martin M Oct 23 '15 at 09:24
-
1Curl 7.47 and this would not work for me. theabraham's answer always defaults to post behavior. --get (or -G) however will force the -d (--data) fields to become url parameters and does work. – James Powell Jun 04 '17 at 01:49
-
So intuitive... – garryp Apr 26 '19 at 10:59
-
Please avoid "localhost:8080" and adopt a real URL like `http://localhost:8080` since the protocol addition is not an intuitive feature and it's not a best practice – Valerio Bozz Mar 02 '23 at 12:20
Quick Answer:
In a single line, the curl command would be:
If sending form data:
curl -X PUT -H "Content-Type: multipart/form-data;" -F "key1=val1" "YOUR_URI"
If sending raw data as json:
curl -X PUT -H "Content-Type: application/json" -d '{"key1":"value"}' "YOUR_URI"
If sending a file with a POST request:
curl -X POST "YOUR_URI" -F 'file=@/file-path.csv'
Alternative solution:
You can use the POSTMAN app from Chrome Store to get the equivalent cURL request. This is especially useful when writing more complicated requests.
For the request with other formats or for different clients like java, PHP, you can check out POSTMAN/comment below.

- 25,759
- 11
- 71
- 103

- 6,644
- 6
- 22
- 26
-
6No idea why this has been downvoted... I copied here the idea how to pass JSON body for curl PUT. Also postman is pretty awesome tool to get curl code for more complicated queries :) – Mikael Lepistö Mar 30 '16 at 14:40
-
2Thanks !! Even I don't have any idea why about the downvotes. Might be reluctance of the users to adopt it. I have created a respo of all my REST apis for mobile in POSTMAN and that is the best productivity tip that I can suggest to anyone working with REST. – Prateek Mar 31 '16 at 06:02
-
Real world example where I'm passing json data and parameter in the end point; curl -X PUT -H "Content-Type: application/json" -d '{"amount":"999","type":"car","parent_id":"12345"}' http://localhost:8080/transactionservice/transaction/2222 – vikramvi Sep 06 '17 at 05:14
-
"Content-Type" header itself makes makes a lot of difference whether your request is accepted or not. Postman is great at that. Many times the api developers themselves do not know what is the actual curl and postman comes to rescue there as well - to dubug the actual Content Type – Prateek Sep 06 '17 at 07:09
-
1Having to install a complete browser (if one doesn't have Chrome) and an extension for it might be an overkill for some people imho. At least you could have provided an alternative for another more common (default installation) web browser like Firefox, where the HttpRequester does a similar job. – rbaleksandar Mar 02 '18 at 13:33
-
-
-
7
-
It might be downvoted because it's non-libre/not open source and some people don't want to recommend such tools. Well I might be a bit dreaming there. There unfortunately not that much resistance to non-libre tools. But more importantly: downvotes shouldn't be used for that. – tuxayo Jun 21 '18 at 13:41
An example PUT following Martin C. Martin's comment:
curl -T filename.txt http://www.example.com/dir/
With -T
(same as --upload-file
) curl will use PUT for HTTP.

- 4,790
- 6
- 41
- 51
-
10Unfortunately, the `-T` is no substitute for `-X PUT` if you want to specify parameters with `-d` or `-F`. `-T` sends the content of a file via PUT. To achieve the `GET` after a redirect, add the parameter `--location` – Martin M Oct 23 '15 at 09:23
-
I am late to this thread, but I too had a similar requirement. Since my script was constructing the request for curl dynamically, I wanted a similar structure of the command across GET, POST and PUT.
Here is what works for me
For PUT request:
curl --request PUT --url http://localhost:8080/put --header 'content-type: application/x-www-form-urlencoded' --data 'bar=baz&foo=foo1'
For POST request:
curl --request POST --url http://localhost:8080/post --header 'content-type: application/x-www-form-urlencoded' --data 'bar=baz&foo=foo1'
For GET request:
curl --request GET --url 'http://localhost:8080/get?foo=bar&foz=baz'

- 1,958
- 1
- 14
- 12
curl -X PUT -d 'new_value' URL_PATH/key
where,
X - option to be used for request command
d - option to be used in order to put data on remote url
URL_PATH - remote url
new_value - value which we want to put to the server's key

- 7,515
- 3
- 24
- 21