# Using rest via rails

**URL:** <https://www.ruby-forum.com/t/using-rest-via-rails/91244>\
**Category:** Rails\
**Created:** [April 5, 2007, 11:14pm UTC](https://www.ruby-forum.com/t/using-rest-via-rails/91244 "2007-04-05T23:14:47Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![daniel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/3ec8ea/32.png) [@daniel](https://www.ruby-forum.com/u/daniel)\
**Post date:** [April 5, 2007, 11:14pm UTC](https://www.ruby-forum.com/t/using-rest-via-rails/91244/1 "2007-04-05T23:14:47Z")

</div>

Hi everyone,  
Im kind of a noob when it comes to RoR. Can anyone point me  
in the right direction to where i can learn how to use rest with RoR.

Basicaly, i have a website that supports rest. I want to create my ror  
application that retrives information from that website via rest.

Thanks for your help

---

<div class="post-metadata">

**Author:** ![daniel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/3ec8ea/32.png) [@daniel](https://www.ruby-forum.com/u/daniel)\
**Post date:** [April 6, 2007, 11:59pm UTC](https://www.ruby-forum.com/t/using-rest-via-rails/91244/2 "2007-04-06T23:59:33Z")

</div>

Daniel,

It would be helpful to have a bit more detail about your needs. Are  
you looking for general information on REST as a concept, the  
particular implementation of REST in Rails, or do you need specific  
information on the REST implementation of this website that you  
mentioned.

For information on REST itself there are many articles available on  
the web about this emerging standard. For information about Rails’  
implementation of REST there’s a general overview in the “Agile Web  
Develop with Rails” book. Another possibly good resource is the  
screen casts over at Peepcode. I haven’t watched it yet, but I hear  
it’s good. For a “Big Picture” view of REST and why Rails has begun  
embracing it, watch DHH’s keynote here:

> **[RailsConf Keynote: David Heinemeier Hansson — ScribeMedia](https://www.scribemedia.org/dhh/)**
>
> We independently review everything we recommend. When you buy through our links, we may earn a commission. Read the full disclosure here. With the release of Rails 1.2, we take a look back at David Heinemeier Hansson’s RailsConf keynote from Chicago....

However, it sounds like you need to communicate with an existing REST  
web service. That’s going to be dependent on that service’s  
implementation of REST. Your best bet there is try to find  
documentation on using their REST interface.

I’ve been seeing a lot of information on REST lately and much of it  
seems very confused. There appears to be much confusion about what  
REST really means.

I like to think about it this way:

First, put aside the idea that you are dealing with a database. The  
database is just a repository to store and retrieve a set of  
resources. Instead think about your application in terms of  
“resources.”

Lets speak in terms of a “book” as one of your application’s  
resources.

You want to perform a set of operations on books:

1. Create new books.
2. List all, or some, of the exiting books.
3. Get one particular book.
4. Make changes to existing books.
5. Delete books.

In terms of Rails these operations might translate to the following  
URLs:

1. POST: [http://localhost:3000/books](http://localhost:3000/books)
2. GET: [http://localhost:3000/books](http://localhost:3000/books)
3. GET: [http://localhost:3000/books/123](http://localhost:3000/books/123)
4. PUT: [http://localhost:3000/books/123](http://localhost:3000/books/123)
5. DELETE: [http://localhost:3000/books/123](http://localhost:3000/books/123)

Notice how some of these URLs refer to your “collection” of books and  
others refer to a particular member of the books collection.

Then there are a couple of additional URL needed to deal with  
resources not directly related to book, but are needed due to the  
nature of the web:

1. GET: [http://localhost:3000/books/new](http://localhost:3000/books/new)
2. GET: [http://localhost:3000/books;edit](http://localhost:3000/books;edit)

I’m not quite sure why the Rails team decided to use “[http://localhost](http://localhost):  
3000/books/new” instead of “[http://localhost:3000/books;new](http://localhost:3000/books;new)” but  
that’s just something you have to remember. Those extensions to the  
GET operations like “/new” or “;edit” can be thought of as “hints” to  
your application that you are asking for the HTML form for either  
entering a new book or modifying an existing book. The HTML forms can  
be thought of as another type of resource in your application that you  
are “GETting.”

Pretty much everything else in RESTful Rails is simply an extension to  
these basic concepts. There are methods for generating the various  
URLs like books\_path() and books\_url(). You can find a nice overview  
of those in the free REST cheat sheet available from [peepcode.com](http://peepcode.com).

There is also the concept of “nested” resources, but I won’t go into  
details on that here. There are other resources (I’ve mentioned a  
few) that go into detail on those. They also discuss how to extend  
your REST routes beyond the basic CRUD operations.

Hope that helps.

Robert
