Create a gist now

Instantly share code, notes, and snippets.

##### ContentType negotiation
# Add a mime type
Pancake::MimeTypes::Type.new("foo", "text/foo")
Pancake::MimeTypes::Type.new("special", "text/plain")
# Group mime types together to simplify responding
Pancake::MimeTypes.group_as(:html, "xhtml", "foo")
Pancake::MimeTypes.group_as(:special, "special", "log")
# Low level usage
Pancake::MimeType.negotiate_accept_type(accept_type, :html, :special)
# Use in a short stack
class MyShortStack < Pancake::Stacks::Short
provides :html, :special
get "/foo(.:format)" do
case content_type
when :html
# respond with html
when :special
# respond with special
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment