![]() |
||
| homebiorecognitionphotosvideoaudiowebcamfriendsstoriestagscontact | ||
Feb 25, 2008 12:53 PMUsing cURL to test RESTful Rails Web ServicesFirst of all the cURL parameters I usually use are: -X [action] Pretty straight forward... let's you specify an action (GET, POST, PUT, DELETE) to take on the URL. > curl -X GET http://localhost:3000/sites > curl -X GET http://localhost:3000/sites.xml > curl -X DELETE http://localhost:3000/sites/1-H [header] This lets you specify your HTTP headers. I usually use Content-type and Accept here. > curl -H "Accept: text/xml" -X GET http://localhost:3000/sites-d [parameter] Again, duh. Let's you specify your parameters to send to the URL - specifically for posting. Note that when using the -d flag, you don't need to specify POST as your action because it's the default. If you're using PUT though, you'll need to add -X PUT. > curl -d "site[site]=broox.com" -d "site[owner]=derek" http://localhost:3000/sites > curl -H "Accept: text/xml" -d "site[site]=broox.com" -d "site[owner]=derek" http://localhost:3000/sitesAnd here's how I use it most often - to POST an XML request to the web service and get an XML response back. > curl -H "Accept: text/xml" -H "Content-type: application/xml" -d "<?xml version ='1.0' encoding 'UTF-8'?> <site><site>broox.com</site><owner>derek</owner></site>" http://localhost:3000/sites Tags: tech CommentsYour Comment |
||
yawn
*yawn*
glad you're doing this all day and not me
4 months ago
derek
well it's either that or post anonymous comments on my blog every few weeks.
4 months ago