Building an API: Rails 3 vs Grape

I’ve been pretty impressed with the Grape Rack library for building an API, but I was curious how it stacks up against Rails 3, now that Rails has been Rack-ified and has steadily become more hospitable to APIs.

Using an existing Rails app with a Grape API mounted as middleware, I ran a benchmark against a vanilla API with this environment:

  • Grape 0.1.5
  • Rails 3.0.10
  • Passenger 3.0.5
  • Ruby Enterprise Edition (ruby 1.8.7), patchlevel 334
  • Macbook Pro, 2.4 GHz / 8GB, OS X 10.6.8

And it looks like Grape wins in this particular environment:

  • Grape averages 47.21 req/sec
  • Rails 3 averages 31.41  req/sec

Grape vs Rails 3 API performance

Here’s how I implemented both scenarios:

Accent theme by Handsome Code


view archive



Ask me anything