Tuesday, May 10, 2011

Tips when using curl to do an HTTP POST !

I have been playing with RestEasy stuff a bit lately and to test my RESTful webservices, I was using curl to do a HTTP GET and POST. To add to the fun, I wanted to use a YAML file as POST payload. I will talk about YAML and RestEasy in a separate blog post, but when you do a POST as


curl -X POST -d @/home/prabhat/house.yaml -H "Content-type: text/x-yaml" http://localhost:8080/eejot-rest/rest/houses


curl strips all newline which is what a browser does. YAML depends on new line and white spaces so that would result into all sort of deserialization issues on server side. The correct way to do instead is


curl -X POST --data-binary @/home/prabhat/payload.yaml -H "Content-type: text/x-yaml" http://localhost:8080/eejot-rest/rest/houses

Curl man page is very clear on this but sometimes we tend to have false assumption. RTFM Prabhat!

No comments: