News

Building an API with Rails at Triangle.rb

Matthew spoke at the Triangle Ruby Brigade this week about building HTTP-based APIs with Rails. Thanks to everyone who came out. We weren’t expecting such a large crowd, and the Q&A afterward was a highlight. It was great to hear how other developers are using APIs in their projects, and what problems they’re running into and solving.

What we covered

Rails is an attractive platform for building APIs, and it’s easy to get started. The talk walked through the basics:

  • Creating an API controller
  • Wiring up versioned routes, so you can change your API without breaking existing clients
  • Protecting the API with authentication
  • Choosing a transport encoding

That last choice matters more than you might think. If your API will be consumed by iOS devices, using binary property lists instead of XML or JSON can give you around a 30% performance boost, along with a matching drop in bandwidth. A couple of Ruby gems make it simple to generate plists from Rails.

Matthew shared code from a recent client project that serves a large, multi-faceted API to hundreds of iOS devices using binary plists, along with resources for anyone who wants to dig deeper.

Update: Video of the talk is now on YouTube.