Politics, Programming and Possibilities
4 Aug
I’ve begun experimenting with the new Edge Rails code that includes built-in support for REST. (The code that was once in the simply_restful plugin is now a part of Edge Rails.) With the capability to generate multiple types of output per action, it has become more and more useful to test actions on the command-line using cURL. Here are some useful cURL parameters I’ve used:
curl -X DELETE http://localhost:3000/books/1
curl -d "book[title]=Test" -d "book[copyright]=1998" http://localhost:3000/books
curl -H "Accept: text/xml" http://localhost:3000/books/sections/1
Putting it all together, here’s a cURL command that updates the title of a Book object using the PUT action and expects an xml response:
curl -H "Accept: text/xml" -X PUT -d "book[title]=Testing Again" http://localhost:3000/books/1
2 Responses for "How to Use cURL to Test RESTful Rails"
What about rake test_functional. What can you not do through your tests, that cUrl can do?
[...] need a client tool. For those who want to use command line only, cURL is highly recommended (see Duane Johnson’s tutorial for how to use it in testing.) However, I want all processes are visual, so I use Rest-Client [...]
Leave a reply