Sha256: 1bd204e44d02342f9c5fcd1eecfb5c4d753f84673154f60a82c4ac397cffc036
Contents?: true
Size: 940 Bytes
Versions: 2
Compression:
Stored size: 940 Bytes
Contents
#!/usr/bin/env ruby # gem install activerecord # gem install mysql2 # create database goliath_test # create user 'goliath'@'localhost' identified by 'goliath' # grant all on goliath_test.* to 'goliath'@'localhost' # create table users (id int not null auto_increment primary key, name varchar(255), email varchar(255)); # insert into users (name, email) values ('dan', 'dj2@everyburning.com'), ('Ilya', 'ilya@igvita.com'); $: << "../../lib" << "./lib" require 'goliath' require 'active_record' require 'yajl' class User < ActiveRecord::Base end class Srv < 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) User.find_by_sql("SELECT SLEEP(10)") [200, {}, User.find(params['id'])] end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
goliath-0.9.4 | examples/activerecord/srv.rb |
goliath-0.9.2 | examples/activerecord/srv.rb |