# RESTful request with parameters?

**URL:** <https://www.ruby-forum.com/t/restful-request-with-parameters/132369>\
**Category:** Rails\
**Created:** [March 19, 2008, 2:13pm UTC](https://www.ruby-forum.com/t/restful-request-with-parameters/132369 "2008-03-19T14:13:27Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![comopasta](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/59ef9b/32.png) [@comopasta](https://www.ruby-forum.com/u/comopasta)\
**Post date:** [March 19, 2008, 2:13pm UTC](https://www.ruby-forum.com/t/restful-request-with-parameters/132369/1 "2008-03-19T14:13:27Z")

</div>

Hi,

I’ve implemented a restful app where I can post comments.  
If I use [http://127.0.0.1:3000/programs/1/comments](http://127.0.0.1:3000/programs/1/comments) I get all the  
comments for program 1

In the main page of the programs I can see all the programs and the LAST  
comment for each program. That I use a helper function that just takes  
the last comment.

Now. I want to do the same thing but the response is sent to a client in  
xml.  
So I can [http://127.0.0.1:3000/programs/1/comments.xml](http://127.0.0.1:3000/programs/1/comments.xml) and again I get  
xml for all the comments.

What is the best way to request the last comment? Using the same request  
but adding a parameter? Creating a custom action?

Thanks

---

<div class="post-metadata">

**Author:** ![comopasta](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/59ef9b/32.png) [@comopasta](https://www.ruby-forum.com/u/comopasta)\
**Post date:** [March 19, 2008, 3:23pm UTC](https://www.ruby-forum.com/t/restful-request-with-parameters/132369/2 "2008-03-19T15:23:43Z")

</div>

On Mar 19, 8:13 am, comopasta Gr [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> What is the best way to request the last comment? Using the same request  
> but adding a parameter? Creating a custom action?

I would add a parameter instead of a custom action:

/programs/1/comments?filter=last

In your controller, you can look at params[:filter] to find out what  
kind of filter the client wants - you could support values like last,  
first, or a number if they want to simply limit the result set.

Jeff

> **[Hey Daddio!](http://softiesonrails.com)**
>
> Home of Hey Daddio Software

---

<div class="post-metadata">

**Author:** ![comopasta](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/59ef9b/32.png) [@comopasta](https://www.ruby-forum.com/u/comopasta)\
**Post date:** [March 19, 2008, 10:21pm UTC](https://www.ruby-forum.com/t/restful-request-with-parameters/132369/3 "2008-03-19T22:21:39Z")

</div>

Jeff C. wrote:

> I would add a parameter instead of a custom action:
> 
> /programs/1/comments?filter=last

Yeah I’ll do it like that. Somehow I get the feeling that adding  
parameters to a clean restful request breaks the rest rules. But I guess  
that is a normal way of doing it.

Thanks!
