Asa Hopkins
2006-Dec-05 21:56 UTC
Interacting with a REST interface from another application
Hey, I''m trying to work out how to hook a couple of my applications together with RESTful APIs. I have done it previously with ActionWebService (both apps are Rails), which kindly provides structures for both creating APIs and calling them. What I''m not clear about is how to set up one application to GET, POST, PUT, or DELETE from another. Perhaps ActiveResource will solve this nicely when it''s ready for prime time, but in the meantime, is there are straightforward way to do this? I guess the heart of my question would be "How do I call a particular URL from within a model or controller, and then process the XML (or whatever it is) that comes back?" Once I can do this, then I still have to work out a nice way to generate the URLs to call, but that I know I can figure out how to do. Thanks, Asa -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Bala Paranj
2006-Dec-07 06:03 UTC
Re: Interacting with a REST interface from another application
Generating XML is very easy in RESTful Rails, consuming it is left to the developer. Any RESTful URL link that ends with xml will fetch the XML document. In your controller you can do something like: require "net/http" begin my_site = Net::HTTP.new("www.mycoolsite.com", 8080) response, data = my_site.get("products.xml", nil) rescue => err puts "Error: #{err}" end puts "Received #{data.split.size} lines, #{data.size} bytes" # Parse your XML document here... Remember that security is not handled here. One way to implement the other http functions is to look at the Rails 1.2 RC1 source code. You will learn a lot from it. HTH.> > I guess the heart of my question would be "How do I call a particular > URL from within a model or controller, and then process the XML (or > whatever it is) that comes back?" Once I can do this, then I still have > to work out a nice way to generate the URLs to call, but that I know I > can figure out how to do. > > Thanks, > Asa--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---