mime_type
というクラスマクロがあります。
以上、よろしくお願いします。
* * *
これだけではあれなのでコードサンプルでも
app.rb
require 'sinatra'
require 'json'
require 'msgpack'
configure do
mime_type :msgpack, "application/x-msgpack"
end
get '/hello.?:format?', :provides => [:json] do
JSON.dump({hello: "world", data: [1, 2, 3, 99]})
end
get '/hello.?:format?', :provides => [:msgpack] do
{hello: "world", data: [1, 2, 3, 99]}.to_msgpack
end
$ ruby app.rb &
$ curl -H "Accept: application/json" http://localhost:4567/hello.json
{"hello":"world","data":[1,2,3,99]}
$ curl -H "Accept: application/x-msgpack" http://localhost:4567/hello.msgpack
��hello�world�data�
$ curl -H "Accept: text/html" http://localhost:4567/hello.json
#=> Sinatra doesn't know this ditty!
Padrino なら
config/apps.rb
で
config/apps.rb
Padrino.configure_apps do
#...
mime_type :msgpack, "application/x-msgpack"
end
こんなんが良さそう。