Rails – speaking REST as a mock webservice

Finally understood the distinctions between webservices and rest. Now I don’t mean the theory aspects Roy Fieldings paper adequately explains the concepts and frankly helps a great deal to try to introduce technology which is along the lines of ‘less is more’.

What I mean is being able to create a service mock up a test script and talk to the server using XML.

Here is an example of creating a new Person:

require 'net/http'

s = <<-XML

Sarah
Jhummun

XML

Net::HTTP.start('localhost', 3000) do |http|
response = http.post('/people.xml', "#{s}", 'Content-Type' => 'text/xml')

#Do something with the response.

puts "Code: #{response.code}"
puts "Message: #{response.message}"
puts "Body:\n #{response.body}"
end

and here is an example of retrieving a list of people:

require 'net/http'

Net::HTTP.start('localhost', 3000) do |http|
response = http.get('/people/', 'Accept' => 'text/xml')

#Do something with the response.

puts "Code: #{response.code}"
puts "Message: #{response.message}"
puts "Body:\n #{response.body}"
end

No related posts.

Related posts brought to you by Yet Another Related Posts Plugin.

  • http://www.google.com KattyBlackyard

    Great post! I’ll subscribe right now wth my feedreader software!

  • http://www.uwsp.edu/ATHLETICS/mbb/05-06/roster.htm Team Roster

    You you could change the post subject title Rails – speaking to rest as a mock webservice | All Thumbs and No Fingers to more catching for your content you write. I loved the blog post however.

  • Paul

    There is a very useful Firefox plugin which provides all HTTP methods to test your web service https://addons.mozilla.org/en-US/firefox/addon/9780/