Created
May 12, 2012 16:29
-
-
Save smd686s/2667467 to your computer and use it in GitHub Desktop.
Goliath.io with Grape and MongoDB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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