Create a simple API with Ruby on Rails

Category: Best Articles    |    784 views    |    1 Comment  |   

Here are the few easy steps to creating a simple API in a Ruby on Rails project.

  • Start a new rails app with the restful_authentication plugin by technoweenie: http://github.com/technoweenie/restful-authentication/
  • The restful_authentication plugin allows for user accounts, but doesn’t have any API authentication built in.  If you want to make publicly available API keys for your users, you’ll need to put this in so you can track API usage and deter any unauthorized use.  So assuming you have restful_authentication all setup with defaults, follow this tutorial for setting up API authentication: http://www.compulsivoco.com/2009/05/rails-api-authentication-using-restful-authentication/
  • Once you have the above api authentication applied, make sure all the actions that you want protected by the API authentication by adding a before filter:

before_filter :login_required, :only => [...array of actions to be protected...]

  • To render out xml for a certain object, you can simply use a respond_to when you’re ready to render xml in the controller.

respond_to do |format|
format.xml { render :xml => @some_object }

Ruby on Rails Resources and TUTORIALS

Category: Tutorials    |    2,110 views    |    2 Comments  |   

 

TUTORIALS

Once you’ve installed Rails it’s time to start coding. Here are a few starting points for you.

Beginner Tutorials

After you’ve installed Rails you should be ready to start developing applications. The following links are starting places for learning the foundations of Ruby, Rails and building your first apps.