mikedhart
mikedhart

Reputation: 423

Posting xml to a rest api in rails

I need to post some xml info to a restful api can anyone give me a clue of how to do this? I'm using rails.

Upvotes: 1

Views: 615

Answers (1)

clyfe
clyfe

Reputation: 23770

In rails, using ActiveResource, you do it like this:

class PersonResource < ActiveResource::Base
  self.site = "http://api.people.com:3000/"
  self.proxy = "http://user:[email protected]:8080"
end

ryan = Person.new(:first => 'Ryan', :last => 'Daigle')
# the next line posts this object serialized to xml to the configured url
ryan.save                # => true

http://api.rubyonrails.org/classes/ActiveResource/Base.html

If the site you are posting to has a custom API (not active resource) you must use Net:HTTP

Upvotes: 2

Related Questions