Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require 'goliath'
- require 'active_record' #mysql2 0.3.7 requires ActiveRecord 3.1
- require 'yajl'
- class User < ActiveRecord::Base
- db_config = {:adapter => 'mysql2', :database => '', :host => '', :username => '', :password => ''}
- establish_connection(db_config)
- end
- class UserService < Goliath::API
- use Goliath::Rack::Params
- use Goliath::Rack::DefaultMimeType
- use Goliath::Rack::Render, 'json'
- # use Goliath::Rack::Validation::RequiredParam, {:key => 'id', :type => 'ID'}
- # use Goliath::Rack::Validation::NumericRange, {:key => 'id', :min => 1}
- def response(env)
- ret = User.find(params['id']).to_json
- [200, {}, ret]
- end
- end
Add Comment
Please, Sign In to add comment