Content negotiation ("Accept" HTTP header) based on routing in symfony2.0

When it comes to REST services, Symfony developers (and cookbooks) tend to base their choice of presentation of resources on a file extension rather than content negotiation ( see this stack 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 to implement proper content negotiation on the server side?

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

+4
source share
1 answer

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

+3
source

Source: https://habr.com/ru/post/1385875/


All Articles