How do i restrict my API to accept & respond only json format on Rails & Grape, i've try format :json
on my Grape controller and (for example) i can access it on example.com/api/v1/ping.json, but i also can access it via example.com/api/v1/ping.xml, example.com/api/v1/ping.foobar, and the list of extensions goes on...
The things i would like to do is, throwing error on example.com/api/v1/ping.not_json_extensions
Im using:
- rails (4.1.1)
- grape (0.7.0)
/config/routes.rb
mount API::Base => '/api'
/controllers/api/base.rb
module API
class Base < Grape::API
mount API::V1::Base
end
end
/controllers/api/v1/base.rb
module API
module V1
class Base < Grape::API
format :json
mount API::V1::Ping
end
end
end
/controllers/api/v1/ping.rb
module API
module V1
class Ping < Grape::API
include API::V1::Defaults
desc 'Returns pong.'
get :ping do
{ ping: params[:pong] || 'pong' }
end
end
end
end