Using CURL to simulate web requests

You can make web requests with CURL for all of the HTTP Verbs (GET, POST, PUT, DELETE) by using the -X and -d arguments as such:

GET Request

curl -X GET http://localhost:8080/api/wines  

POST Request

curl -X POST -d "name=hello&country=USA&region=california" http://localhost:8080/api/wines  

PUT Request

curl -X PUT -d "id=3&name=hello&country=USA&region=california&year=2007" http://localhost:8080/api/wines/3  

DELETE Request

curl -X DELETE http://localhost:8080/api/wines/3  

JSON Data

To send JSON data, use -H "application/json" header option and pass in the stringified version of your JSON payload as the data.

curl -X POST -H "Content-Type: application/json" -d '{"name":"Brian", age:33}' http://localhost:8080/api/person  

Don't forget to make your JSON valid. Keys need to be inside quotes!

comments powered by Disqus