Created
July 15, 2012 20:42
-
-
Save rinaldifonseca/3118546 to your computer and use it in GitHub Desktop.
EM-Mongo with Goliath
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
config['mongo'] = EventMachine::Synchrony::ConnectionPool.new(size: 20) do | |
conn = EM::Mongo::Connection.new('localhost', 27017, 1, {:reconnect_in => 1}) | |
conn.db('muisco') | |
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
require 'goliath' | |
require 'em-synchrony' | |
require 'em-synchrony/em-mongo' | |
# automatically parse the JSON HTTP response | |
class Track < Goliath::API | |
use Goliath::Rack::Params | |
use Goliath::Rack::Render, 'json' | |
use Goliath::Rack::JSONP | |
use Goliath::Rack::Validation::RequestMethod, %w(GET) | |
def response(env) | |
coll = mongo.collection('users') | |
res = coll.afind({}).to_a | |
payload = {:results => res} | |
[200, {}, payload] | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment