# Augmenting RESTful routes to make it more informative

**URL:** <https://www.ruby-forum.com/t/augmenting-restful-routes-to-make-it-more-informative/144547>\
**Category:** Rails\
**Created:** [July 30, 2008, 9:01pm UTC](https://www.ruby-forum.com/t/augmenting-restful-routes-to-make-it-more-informative/144547 "2008-07-30T21:01:30Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![mhfs](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/b2d939/32.png) [@mhfs](https://www.ruby-forum.com/u/mhfs)\
**Post date:** [July 30, 2008, 9:01pm UTC](https://www.ruby-forum.com/t/augmenting-restful-routes-to-make-it-more-informative/144547/1 "2008-07-30T21:01:30Z")

</div>

Everyone knows that the trend is RESTful design. The simplicity of REST  
means that if makes it easier to create bigger and more complex object  
models.

As a side effect, you have your RESTful routes/URLs, which reflect the  
simplicity and consistency of the RESTful design. It is natural to model  
your URLs after your objects, object hierarchies instead of actions (the  
actions being the HTTP verbs).

RESTful route:  
/events/3

However, sometimes there are specific routes that don’t really fit into  
the  
RESTful way of doing things but are useful nonetheless. For example:

/events/04/06/2007/3

This url adds a prefix date to the event/events. Besides allowing the  
user  
to list all of the events of a specific date, it is also very  
informative.  
Having this additional piece of information in a google search result  
can  
sometimes be a timesaver (you can be more certain that it is the event  
you  
are searching, since the one you went to also happened on this date).

I don’t know if this date could be re-factored into a resource. The way  
I’m  
doing this is customizing the default events resource RESTful route to  
have  
this prefix.

Do you have such custom URLs in your app? Would you mind sharing your  
thoughts and experiences?

Thanks in advance,

Marcelo

---

<div class="post-metadata">

**Author:** ![mhfs](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/b2d939/32.png) [@mhfs](https://www.ruby-forum.com/u/mhfs)\
**Post date:** [August 11, 2008, 5:57pm UTC](https://www.ruby-forum.com/t/augmenting-restful-routes-to-make-it-more-informative/144547/2 "2008-08-11T17:57:43Z")

</div>

On Jul 30, 1:59 pm, “Marcelo de Moraes S.” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> Having this additional piece of information in a google search result can  
> Thanks in advance,
> 
> Marcelo

I think the only issue here is the use of forward slashes in the url.  
If you could do this instead:

/events/04-06-2008

then this would work with the default map.resources behavior, and be  
easily consumable by your show or index actions:

# you should actually sanitize your input first, of course

@event = Event.find\_by\_date(Date.parse(params[:id]))

# or

@events = Event.find\_all\_by\_date(Date.parse(params[:id]))

Hope this helps?

Jeff

Come to REST with Rails, Oct 4, 2008 in Austin, TX:  
[http://www.purpleworkshops.com/workshops/rest-and-web-services](http://www.purpleworkshops.com/workshops/rest-and-web-services)

[softiesonrails.com](http://softiesonrails.com) - blog  
[purpleworkshops.com](http://purpleworkshops.com) - training  
[pragprog.com/titles/cerailn](http://pragprog.com/titles/cerailn) - Upcoming book, Rails for .NET Developers
