How to do a PUT request with curl?

Using the -X flag with whatever HTTP verb you want:

curl -X PUT -d arg=val -d arg2=val2 localhost:8080

This example also uses the -d flag to provide arguments with your PUT request.


Quick Answer:

In a single line, the curl command would be:

  1. If sending form data:

    curl -X PUT -H "Content-Type: multipart/form-data;" -F "key1=val1" "YOUR_URI"
    
  2. If sending raw data as json:

    curl -X PUT -H "Content-Type: application/json" -d '{"key1":"value"}' "YOUR_URI"
    
  3. 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.

POSTMAN to get the request code

Tags:

Http

Rest

Curl