cURL: PUT request examples
cURL HTTP PUT request examples with my most frequently used command-line options.
The examples for PUT are very similar to those detailed in my post explaining how to do POST requests in cURL.
HTTP PUT request
The most basic command you can execute with cURL is an HTTP PUT request without a body.
To tell cURL to use a PUT request method we can use the -X, --request command-line option, the following command will perform the request using the PUT verb and output the response body:
curl -X PUT https://blog.marcnuri.comHTTP PUT request with data
If you want to send some data with the PUT request, you can use the -d, --data command-line option. When using the data option, cURL sends data just like your browser would when you fill an HTML form and press the submit button. In addition, cURL will automatically add the Content-Type header with an application/x-www-form-urlencoded value.
curl -X PUT -d "field=value&tool=curl" https://postman-echo.com/putHTTP PUT request with JSON data
To send JSON content in the request body of your HTTP PUT request, you need to use the -d, --data options in combination with a custom Content-Type header (-H, --header).
curl -X PUT -d '{"field":"value"}' -H "Content-Type: application/json" https://postman-echo.com/putJSON from file
In case you want to load the JSON content from a file instead of providing it via command-line, you can load it using the @ symbol followed by the path to the file that contains the JSON data:
curl -X PUT -d "@file-with-json.json" -H "Content-Type: application/json" https://postman-echo.com/putSummary
These are some of the common cURL PUT HTTP request examples I use on a daily basis. I hope they may come in useful for you too.
