Created
January 6, 2011 16:55
-
-
Save mtodd/768156 to your computer and use it in GitHub Desktop.
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
helpers do | |
def format | |
(params[:format] || :json).to_sym | |
end | |
def render_to(format, results) | |
case format | |
when :json | |
results.to_json | |
when :xml | |
results.to_xml | |
end | |
end | |
end | |
before do | |
not_found unless params.key?(:query) | |
end | |
not_found do | |
render_to(format, {:error => "Not Found", :status => 404}) | |
end | |
get '/api/v1/noun.:format' do | |
render_to(format, params[:query]) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment