My goal is to have a default json output when the user agent is set to anything else than json or xml. I have configured FOSRestBundle 1.1.0 as follows:
fos_rest:
format_listener: true
param_fetcher_listener: true
view:
default_engine: php
formats:
json: true
xml: true
templating_formats:
html: false
view_response_listener: force
routing_loader:
default_format: json
This works. Now I added the following configuration:
format_listener:
rules:
- { fallback_format: json, prefer_extension: false, priorities: ['xml', 'json'] }
As soon as I do that, I can no longer switch between formats by either appending ?_format=json
or ?_format=xml
and also the Accept header seems to be ignored, it always uses whatever I specify in the accept header.
How to configure FOSRestBundle so that it accepts json or XML via Parameter/HTTP Request header and falls back to json if the format accepted by the browser is HTML?