# Creating a REST Client

**URL:** <https://www.ruby-forum.com/t/creating-a-rest-client/137341>\
**Category:** Rails\
**Created:** [May 12, 2008, 7:21am UTC](https://www.ruby-forum.com/t/creating-a-rest-client/137341 "2008-05-12T07:21:10Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![sameera](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/b487fb/32.png) [@sameera](https://www.ruby-forum.com/u/sameera)\
**Post date:** [May 12, 2008, 7:21am UTC](https://www.ruby-forum.com/t/creating-a-rest-client/137341/1 "2008-05-12T07:21:10Z")

</div>

Hi all,

I would like to create a RESTful rails application. My idea is to have 2  
web sites.  
1 - REST server. This will have all the methods (Ex: getName())  
2 - REST client. This will be another website which will call the above  
server web method and display the details.

I was manage to create the Server part with rails 2. But my problem is  
how do i create the web client. because most of the RESTClients examples  
has command line output using curl.

can anyone tell me how to develop a web page to display the details from  
a REST method.

i’m using rails 2.0.2

thank you in advance

cheers  
sameera

---

<div class="post-metadata">

**Author:** ![sameera](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/b487fb/32.png) [@sameera](https://www.ruby-forum.com/u/sameera)\
**Post date:** [May 13, 2008, 2:32am UTC](https://www.ruby-forum.com/t/creating-a-rest-client/137341/2 "2008-05-13T02:32:59Z")

</div>

A couple of this that will hopefully get you on the right track:

1. What you’re looking for is ActiveResource. This is explained in  
documentation so I won’t go into a lot of detail here.
2. Your example (getName()) is actually not in-line with the REST  
architecture. Let me explain.

REST (especially as it is approached in Rails) is all about resources  
and using the REST verbs to access them. I’m guessing that name is not  
actually a resource in your application that you would “get.” Also, in  
a RESTful application the verb “get” would not appear in your method  
names.

The more likely case is that “name” would be an attribute of some  
resource, say “Person.” Then you would access people though the  
RESTful resource URLs by applying the proper verb (GET, POST, PUT,  
DELETE).

So if you wanted to get all the people you would send a GET request to  
the “[http://mydomain.com/people](http://mydomain.com/people)” URL, which would return a result in a  
given format (HTML by default). For use by a client application the  
format would typically be XML. So to ask the resource for XML format  
you would access the “[http://mydomain.com/people.xml](http://mydomain.com/people.xml)” URL.

Now if you want to access a specific resource id you would send a GET  
to the “[http://mydomain.com/people/25](http://mydomain.com/people/25)” url or "“[http://mydomain.com/](http://mydomain.com/)  
people/25.xml” URL.

To perform the other operations on the resource you use the same URLs,  
but instead use the appropriate verb. For example send a POST request  
to the same “collection” URL “[http://mydomain.com/people](http://mydomain.com/people)” to create a  
new person. Send a “member” URL "“[http://mydomain.com/people/25](http://mydomain.com/people/25)” a PUT  
request to update it’s attributes or a DELETE request to destroy it.

As I mentioned in #1 above: ActiveResource knows about all this, and  
allows you to access your remote resources almost exactly like you  
would access them with ActiveRecord.

On May 12, 1:21 am, Sameera G. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![sameera](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/b487fb/32.png) [@sameera](https://www.ruby-forum.com/u/sameera)\
**Post date:** [May 15, 2008, 5:21pm UTC](https://www.ruby-forum.com/t/creating-a-rest-client/137341/3 "2008-05-15T17:21:41Z")

</div>

I’d suggest you concentrate on the main app first. It’s a bit of a  
waste of time to try to figure this out before you have anyone even  
remotely interested in your app to begin with.

REST, however, has only marginal impact on your desire to allow games  
into your main app. The primary use of REST for the gamers would be  
to get access into your user/friends/etc models. Check out the  
facebook api; I don’t think you get much more than that. With that in  
mind you can provide some authentication/authorization around the REST  
interface for the appropriate controllers so the game makers can’t  
pervert your data and not much more. REST will probably have very  
little to do with how you pull a third party app into your main app.

On May 14, 7:28 am, Sameera G. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![sameera](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/b487fb/32.png) [@sameera](https://www.ruby-forum.com/u/sameera)\
**Post date:** [May 14, 2008, 1:28pm UTC](https://www.ruby-forum.com/t/creating-a-rest-client/137341/4 "2008-05-14T13:28:10Z")

</div>

Hi Walker

First of all thank you for your reply. I has given me some good points  
to start off.

actually my ultimate goal is to develope a main application and out side  
developers can develop applications to it. (Like facebook does.)

I’m thinking of having a main web application and inside an iframe 3rd  
party web apps will run.

for that i think its better to use RESTful way (in the main app) so that  
others can communicate with it.

I dont know whether i sounds stupid… Please correct me if i’m going in  
the wrong direactions…

any comments, thoughts direactions would be appriciated…

and thankx again for the reply

cheers  
sameera

---

<div class="post-metadata">

**Author:** ![sameera](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/b487fb/32.png) [@sameera](https://www.ruby-forum.com/u/sameera)\
**Post date:** [July 22, 2008, 3:55am UTC](https://www.ruby-forum.com/t/creating-a-rest-client/137341/5 "2008-07-22T03:55:44Z")

</div>

Hi, Hope you have managed to solve your problem. Heres is what you have  
to do. I guess You have managed to make a rest server and you want to  
proceed to making the rest client which has to be capable of making  
restful calls to the server, All four methods of http. There are  
numerous options…

first option : Make use of open-uri or net/http libraries , these will  
enable you to make http calls to the server from form the remote client  
application.

second option: Make use of activeresource library, it will enable you  
the bypass the limitations you had using open-uri that means you can  
make all four method calls to the server.

option Three: Make us of ajax, Make ajax client and work by utilizing  
xmlhttp request which will enable you making all restful calls to the  
server.

Sameera G. wrote:

> Hi all,
> 
> I would like to create a RESTful rails application. My idea is to have 2  
> web sites.  
> 1 - REST server. This will have all the methods (Ex: getName())  
> 2 - REST client. This will be another website which will call the above  
> server web method and display the details.
> 
> I was manage to create the Server part with rails 2. But my problem is  
> how do i create the web client. because most of the RESTClients examples  
> has command line output using curl.
> 
> can anyone tell me how to develop a web page to display the details from  
> a REST method.
> 
> i’m using rails 2.0.2
> 
> thank you in advance
> 
> cheers  
> sameera
