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