All Thumbs and No Fingers A bucket for all things

27Feb/091

Rails – speaking to 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

Related posts:

  1. Secure Copy How to Heres a rough and ready introduction to using the power...

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

Tagged as: , Leave a comment
Comments (1) Trackbacks (0)
  1. Great post! I’ll subscribe right now wth my feedreader software!


Leave a comment


No trackbacks yet.

Pages

Amazon Favs:

new posts

My Photos

Bright blue skies

Sarah in the hamock

We won the drinks list!

Charlie's morning feeding ritual for sooty

More Photos

tag cloud

accessibility apple astronomy navigation observatory british beck bug council design development dunning kruger psychology elearning facebook flash flickr browsing web photos pictures general i8n induction wordpress opensource resuse iphone itunes javascript languages learning localisation localise mehrabian motorcycle music myth my_learning parking plan programing programming proxy rails rest socks ssh star synth tech iphone travel theme threshold money value spending tips health weight obesity advice welcome words

categories

Blogroll

Life is too short

Friends