Skip to content

Instantly share code, notes, and snippets.

@mtodd
Created January 6, 2011 16:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mtodd/768156 to your computer and use it in GitHub Desktop.
Save mtodd/768156 to your computer and use it in GitHub Desktop.
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