ma1*_*w28 46 ruby json content-type sinatra
在Sinatra,是否可以content_type 'application/json'
设置默认值?因为我正在写一个api.
Ada*_*sek 75
当然,添加content_type
到before
回调:
class MyApp < Sinatra::Base
before do
content_type 'application/json'
end
...
end
Run Code Online (Sandbox Code Playgroud)
Sinatra 1.1在过滤器之前引入了模式匹配:
before '/admin/*' do
check_logged_in
end
Run Code Online (Sandbox Code Playgroud)
对于 JSON API,为所有响应设置默认值的最推荐方法Content-Type
是在 Sinatra 类中添加以下内容:
set :default_content_type, :json
Run Code Online (Sandbox Code Playgroud)
它将Content-Type: application/json
在您的所有回复中包含一个标头。
归档时间: |
|
查看次数: |
21718 次 |
最近记录: |