Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tutorials or screencasts on building a REST web service on Rails [closed]

I am looking to build a REST webservice on Rails to serve as the server side component to my mobile app. Can someone point out some tutorials or screencasts on building REST webservices for someone who is learning Rails?

The main features I am looking for are:

  1. Authorization(user id and password validation).
  2. Posting data from the client (mobile app) to the server database using REST API

I am also okay if you could point me to some book where content on creating a rest api is available.

It would also be great if someone could post a bit of code to get me started on this.

I am relatively new to Rails and have almost finished the book "Ruby on Rails Tutorials" by Michael Hartl. This is my only experience with Rails, so far.

Thanks.

like image 425
rogerstone Avatar asked May 23 '11 15:05

rogerstone


2 Answers

I wrote 2 blog posts that you'll probably find helpful:

http://davidsulc.com/blog/2011/04/10/implementing-a-public-api-in-rails-3/

http://davidsulc.com/blog/2011/04/17/consuming-a-public-rails-api-with-jquery/

They're not tutorials, but it should get you going.

The basic idea is: expose JSON data through controller actions when a request is made with the .json format.

Cross domain requests (like the ones you'll be doing from your mobile app) are a little trickier, as explained in the blog post: you'll actually need to send javascript within a callback, or your code won't work (you'll get an empty response). (Explained in the first post.)

Once the data is exposed as JSON, simply query it from your mobile app (as explained in the 2nd post).

EDIT: Manning has a book on Rails 3 (one of the authors being none other than Yehuda Katz) with a chapter on creating an API: http://manning.com/katz/ In particular, it covers token authorization for the API using Devise.

like image 134
David Sulc Avatar answered Oct 20 '22 22:10

David Sulc


I'd suggest you visit Railscasts. If you search on various keywords you'll get a wealth of information. I used 'REST', 'routes', 'controller' to get myself started...

like image 25
jaydel Avatar answered Oct 20 '22 21:10

jaydel