content negotiation (“Accept” HTTP header) based r

2019-04-10 16:20发布

问题:

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?

回答1:

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



标签: rest symfony