In Sinatra is it possible to make content_type 'application/json'
the default? Because I'm building a REST API.
Sure, add content_type
to the before
callback:
class MyApp < Sinatra::Base
before do
content_type 'application/json'
end
...
end
Sinatra 1.1 introduces pattern-matching before filters:
before '/admin/*' do
check_logged_in
end
For a JSON API the most recommendable way to set a default Content-Type
for all your responses is to add the following in your Sinatra class:
set :default_content_type, :json
It will include a Content-Type: application/json
header in all your responses.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With