apiary: Event Machine API in a box for your Ruby classes

If you need to stand up an API for your Ruby web application, you’ve got a lot of choices including Rails, Sinatra, even close-to-the-metal Rack, or Grape.

But, if you’ve got some simple Ruby classes that you’d like to expose directly as a web-based API take a look at Joshua Hull’s Apiary.

Apiary uses Thin and some Event Machine goodness to let you declare methods in your Ruby classes as API methods:

class Temperature
  include Apiary              # Include Apiary as a module in your class

  version '1.0'               # Specifies a version prefix for your api

  get                         # Marks this method as accessible from GET
  def c2f(val)                # This is now available at /1.0/c2f/:val
    Float(val) * 9 / 5 + 32

You can start your Temperature API server with Temperature.run. Apiary will crank up Thin and listen to requests on port 3000:

curl http://localhost:3000/1.0/c2f/23.45

Apiary is brand new and will likely change, but it looks promising.

[Source on GitHub]

News Films

Our little film studio focuses on telling developer-centric stories that need to be seen.

Beyond Code: Season 3 / GopherCon 2015

0:00 / 0:00