Guest User

Untitled

a guest
Jan 23rd, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. require 'goliath'
  2. require 'active_record' #mysql2 0.3.7 requires ActiveRecord 3.1
  3. require 'yajl'
  4.  
  5. class User < ActiveRecord::Base
  6. db_config = {:adapter => 'mysql2', :database => '', :host => '', :username => '', :password => ''}
  7. establish_connection(db_config)
  8. end
  9.  
  10. class UserService < Goliath::API
  11. use Goliath::Rack::Params
  12. use Goliath::Rack::DefaultMimeType
  13. use Goliath::Rack::Render, 'json'
  14.  
  15. # use Goliath::Rack::Validation::RequiredParam, {:key => 'id', :type => 'ID'}
  16. # use Goliath::Rack::Validation::NumericRange, {:key => 'id', :min => 1}
  17.  
  18. def response(env)
  19. ret = User.find(params['id']).to_json
  20. [200, {}, ret]
  21. end
  22. end
Add Comment
Please, Sign In to add comment