问题描述
谈到 REST 服务时,Symfony 开发人员(和说明书)倾向于根据文件扩展名而不是内容协商(参见这个 stackoverflow 问题).
When it comes to REST services, Symfony developers (and cookbooks) tend to base the choice of resource representation on file extension rather than content negotiation (see this stackoverflow question).
示例:
article_show:
pattern: /articles/{culture}/{year}/{title}.{_format}
defaults: { _controller: AcmeDemoBundle:Article:show, _format: html }
requirements:
culture: en|fr
_format: html|rss
year: \d+
是否有在服务器端实现适当内容协商的捆绑包/方式?
Is there a Bundle/way of implementing proper content negotiation on the server side?
在控制器中使用 _format
和 encoders
实现 switch/case 风格的算法是达到目标的唯一方法吗?
Implementing a switch/case style algorithm with _format
and encoders
in the Controller is the only way to get there?
推荐答案
结帐 https://github.com/FriendsOfSymfony/FOSRestBundle,格式侦听器"部分...
Checkout https://github.com/FriendsOfSymfony/FOSRestBundle, section "Format listener" ...
这篇关于symfony2.0 中基于内容协商(“接受"HTTP 标头)的路由的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!