Last active
August 29, 2015 14:11
-
-
Save sholfen/0bf1b2411f42028b9110 to your computer and use it in GitHub Desktop.
Sinatra Test
This file contains hidden or 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
# 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