Creating a REST Client

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

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" 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" URL.

Now if you want to access a specific resource id you would send a GET to the "http://mydomain.com/people/25" url or ""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" to create a new person. Send a "member" URL ""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.

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

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.