# Rails and REST

**URL:** <https://www.ruby-forum.com/t/rails-and-rest/119129>\
**Category:** Rails\
**Created:** [November 3, 2007, 1:48pm UTC](https://www.ruby-forum.com/t/rails-and-rest/119129 "2007-11-03T13:48:09Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jamal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/35a633/32.png) [@jamal](https://www.ruby-forum.com/u/jamal)\
**Post date:** [November 3, 2007, 1:48pm UTC](https://www.ruby-forum.com/t/rails-and-rest/119129/1 "2007-11-03T13:48:09Z")

</div>

Hello,

I was wondering how do I use the respond\_to xml ?

class PeopleController \< ApplicationController  
def index  
@peope = People.find(:all)  
respond\_to do | request |  
request.html { }  
request.xml { render :xml =\> @people…to\_xml(:except =\> [:id])  
}  
end  
end  
end

I tried with this and I always get execution timeout?

result = Net::HTTP.get(URI(‘[http://localhost:3000/people](http://localhost:3000/people)’))  
@people = REXML::Document.new(result)

How can I get the my index to response with XML?

Thanks for any help 🙂

---

<div class="post-metadata">

**Author:** ![jamal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/35a633/32.png) [@jamal](https://www.ruby-forum.com/u/jamal)\
**Post date:** [November 3, 2007, 3:09pm UTC](https://www.ruby-forum.com/t/rails-and-rest/119129/2 "2007-11-03T15:09:00Z")

</div>

On Nov 3, 2007, at 1:48 PM, Jamal S. wrote:

> class PeopleController \< ApplicationController  
> def index  
> @peope = People.find(:all)  
> respond\_to do | request |  
> request.html { }  
> request.xml { render :xml =\> @people…to\_xml(:except =\>  
> [:id])

The couple of dots is a typo.

> result = Net::HTTP.get(URI(‘[http://localhost:3000/people](http://localhost:3000/people)’))  
> @people = REXML::Document.new(result)
> 
> How can I get the my index to response with XML?

If you have declared

map.resources :people

then you can specify the desired “xml” format this way:

[http://localhost:3000/people.xml](http://localhost:3000/people.xml)

– fxn

---

<div class="post-metadata">

**Author:** ![jamal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/35a633/32.png) [@jamal](https://www.ruby-forum.com/u/jamal)\
**Post date:** [November 3, 2007, 5:43pm UTC](https://www.ruby-forum.com/t/rails-and-rest/119129/3 "2007-11-03T17:43:26Z")

</div>

On 3 Nov 2007, at 12:48, Jamal S. wrote:

> I tried with this and I always get execution timeout?
> 
> result = Net::HTTP.get(URI(‘[http://localhost:3000/people](http://localhost:3000/people)’))  
> @people = REXML::Document.new(result)

Are you doing this from the same rails app? in dev mode you typically  
only have 1 mongrel, if 1 is busy executing the above code that leaves  
no one to handle the request you;re making.

On top of that you need to tell it you want xml. You can either do  
this by setting the Accept header or by saying you want people.xml  
(assuming you’ve got the standard routes setup)

Fred
