Testing your RESTful api from CURL

Posted by Tieg Zaharia Tue, 03 Jul 2007 19:21:00 GMT

Many people use the command-line tool curl for testing their web app's api. Here's a quick way to test your api with a multipart request using curl:
 curl -F "song[uploaded_data]=@Music/Fugazi-Break.mp3" http://my.jukebox.app/songs.xml
The -F parameter automatically turns the request into a POST (so you don't need the -X parameter), so in your Rails app this URL will call the SongsController#Create() method. "@" passes the entire file into the form, but you could use "<" instead to just assign the contents of the file to the form field.

Also, you might run into a 417 http error with some servers like Lighttpd. In that case you need to send an Expect header, like so:
 curl -H "Expect:" -F "song[uploaded_data]=@Music/Fugazi-Break.mp3" http://my.jukebox.app/songs.xml