cURL – PUT request examples

Example to use cURL -X PUT to send a PUT (update) request to update the user’s name and email.

Terminal

$ curl -X PUT -d 'name=mkyong&email=abc@gmail.com' http://localhost:8080/user/100

If the REST API only accepts json formatted data, try this

Terminal

$ curl -X PUT -H "Content-Type: application/json" -d '{"name":"mkyong","email":"abc@gmail.com"}' http://localhost:8080/user/100

References

  1. cURL official website
  2. cURL – POST request examples

About the Author

author image
mkyong
Founder of Mkyong.com, love Java and open source stuff. Follow him on Twitter, or befriend him on Facebook or Google Plus. If you like my tutorials, consider make a donation to these charities.

Comments

avatar
3 Comment threads
2 Thread replies
1 Followers
 
Most reacted comment
Hottest comment thread
5 Comment authors
VenugopalDrew ForbesAnnamalai TmkyongMatt Recent comment authors
newest oldest most voted
Annamalai T
Guest
Annamalai T

Nice Tutorial

Venugopal
Guest
Venugopal

Very useful and informative. Thank you for sharing.

Matt
Guest
Matt

PUT is not for update – it is for creation, POST is for update (as the comment states update)

Drew Forbes
Guest
Drew Forbes

In my opinion, a PUT can be used for a create if a second PUT with the same data would result in no change and no new record. Sending two POSTs with the same data should create two separate records.

You can find some great discussion on this question here: https://stackoverflow.com/questions/630453/put-vs-post-in-rest