content negotiation (“Accept” HTTP header) based r

2019-04-10 16:15发布

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).

Example:

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?

Implementing a switch/case style algorithm with _format and encoders in the Controller is the only way to get there?

标签: rest symfony
1条回答
劫难
2楼-- · 2019-04-10 16:36

Checkout https://github.com/FriendsOfSymfony/FOSRestBundle, section "Format listener" ...

查看更多
登录 后发表回答