Skip to content

Instantly share code, notes, and snippets.

@smd686s
Created May 12, 2012 16:29
Show Gist options
  • Save smd686s/2667467 to your computer and use it in GitHub Desktop.
Save smd686s/2667467 to your computer and use it in GitHub Desktop.
Goliath.io with Grape and MongoDB
require 'goliath'
require 'em-synchrony'
require 'em-synchrony/em-mongo'
require 'grape'
class API < Grape::API
version 'v1', :using => :path
format :json
resource 'clients' do
# http://0.0.0.0:9000/v1/clients/
get "/" do
coll = env.mongo.collection('clients') #Connection Pool from Goliath ENV
coll.find({})
end
end
end
class App < Goliath::API
def response(env)
API.call(env)
end
end
#this should live in a file called app.rb inside a directory called 'config'
config['mongo'] = EventMachine::Synchrony::ConnectionPool.new(size: 20) do
conn = EM::Mongo::Connection.new('localhost', 27017, 1, {:reconnect_in => 1})
conn.db('db')
end
gem 'mongo'
gem 'em-mongo'
gem 'bson_ext'
gem 'goliath'
gem 'grape'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment