Created
April 8, 2009 12:59
-
-
Save jptix/91757 to your computer and use it in GitHub Desktop.
This file contains 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
require "rubygems" | |
require "rack/contrib/accept_format" # sudo gem install rack-rack-contrib (http://github.com/rack/rack-contrib/tree/master) | |
require "sinatra" | |
require "yaml" | |
require "json" | |
use Rack::AcceptFormat | |
get "/foo.*" do | |
@data = %w[foo bar baz] | |
pass | |
end | |
get "/foo.html" do | |
"<ul>" + @data.map { |n| "<li>#{n}</li>"}.join("\n") + "</ul>" | |
end | |
get "/foo.yaml" do | |
@data.to_yaml | |
end | |
get "/foo.json" do | |
@data.to_json | |
end | |
=begin | |
$ curl localhost:4567/foo | |
<ul><li>foo</li> | |
<li>bar</li> | |
<li>baz</li></ul> | |
$ curl localhost:4567/foo --header "Accept: application/json" | |
["foo","bar","baz"] | |
$ curl localhost:4567/foo --header "Accept: text/yaml" | |
--- | |
- foo | |
- bar | |
- baz | |
=end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment