【问题标题】:content negotiation ("Accept" HTTP header) based routing in symfony2.0symfony2.0 中基于内容协商(“Accept”HTTP 标头)的路由
【发布时间】:2011-12-12 11:10:39
【问题描述】:

在 REST 服务方面,Symfony 开发人员(和说明书)倾向于根据文件扩展名而不是内容协商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+

是否有在服务器端实现正确内容协商的 Bundle/方式?

在 Controller 中使用 _formatencoders 实现 switch/case 样式算法是实现目标的唯一方法吗?

【问题讨论】:

    标签: rest symfony


    【解决方案1】:

    结帐https://github.com/FriendsOfSymfony/FOSRestBundle,“格式侦听器”部分...

    【讨论】:

    • 非常不错的捆绑包。处理 both 内容协商(使用后备格式)和 URL 中的“常规”格式 slug。谢谢!
    • 大家好,很抱歉提出一个旧线程,但我想知道是否可以使用此侦听器根据接受标头选择路由?基本上我的应用程序是使用spine 的客户端,所以如果它是一个AJAX 请求,我想照常使用FOSRestBundle,但是如果有人将相同的URL 敲入浏览器,它会加载base.html.twig 文件。我能做到这一点的唯一方法是使用 if 语句查看我传入的请求变量。
    猜你喜欢
    • 2020-03-06
    • 2015-04-01
    • 2010-12-31
    • 1970-01-01
    • 2012-12-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-05-06
    相关资源
    最近更新 更多