Skip to content

Instantly share code, notes, and snippets.

@sholfen
Last active August 29, 2015 14:11
Show Gist options
  • Save sholfen/0bf1b2411f42028b9110 to your computer and use it in GitHub Desktop.
Save sholfen/0bf1b2411f42028b9110 to your computer and use it in GitHub Desktop.
Sinatra Test
# myapp.rb
require 'sinatra'
require 'yajl'
require 'json'
encoder = Yajl::Encoder.new
get '/' do
'Hello world!'
end
get '/aaa3' do
resource =
{
:foo=>"bar",
:baz=>"qux",
:my=>{:a=>"aaa3",:b=>true}
}
#encoder = Yajl::Encoder.new
content_type :json
encoder.encode(resource)
#json resource
end
post '/aaa4' do
#params[:Foo]
data = JSON.parse request.body.read
#{}"Hello #{data['name']}!"
data['Foo']
end
get '/aaa5' do
content_type :json
result = {:aaa3=>"3065", :aaa4=>"5678"}
encoder.encode(result)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment