symfony2.0 中基于内容协商(“接受"HTTP 标头)的路由 [英] content negotiation ("Accept" HTTP header) based routing in symfony2.0

查看:34
本文介绍了symfony2.0 中基于内容协商(“接受"HTTP 标头)的路由的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

谈到 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?

在控制器中使用 _formatencoders 实现 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 标头)的路由的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆