August 04, 2006

Posted by John

Tagged rest and testing

Older: Finally A Great Basic Testing Article

Newer: Switched to Mephisto

How to Use cURL to Test RESTful Rails

Duane Johnson just posted tutorial on how to use cURL to test a RESTful Rails app. A few of his examples are below.

  • -X [action]: Allows you to specify an HTTP action such as GET, POST, PUT or DELETE.

    curl -X DELETE http://localhost:3000/books/1
  • -d [parameter]: Lets you set variables as if they were POSTed in a form to the URL. Note that this automatically makes the request a POST HTTP action type (no -X necessary).

    curl -d "book[title]=Test" -d "book[copyright]=1998"
  • -H [header]: Gives you the option of setting an HTTP header such as Content-Type or Accept. This is particularly useful for requesting text/xml as the Accept type.

    curl -H "Accept: text/xml"

Be sure to check it out if you have been looking into CRUD and edge Rails.


Sorry, comments are closed for this article to ease the burden of pruning spam.


Authored by John Nunemaker (Noo-neh-maker), a web developer and programmer who has fallen deeply in love with Ruby. More about John.


Feed IconRailsTips Articles - An assortment of howto's and thoughts on Ruby and Rails.

Feed IconRails Quick Tips - Ruby and Rails related links.