Question

I'm using the friendsofsymfony/rest-bundle": "1.0.*@dev" bundle, trying to upgrade from Symfony 2.2 to Symfony 2.3. In my app/config/config.yml file, I'm trying to specify rules for the fos_rest format_listener:

fos_rest:
    view:
        formats:
            rss: false
            xml: true
            json: true
        templating_formats:
            html: true
        force_redirects:
            html: true
            json: true
        failed_validation: HTTP_BAD_REQUEST
        default_engine: twig
    format_listener:
        rules:
                fallback_format: json
                prefer_extension: true

When I do this and I run composer.phar install, it says

[Symfony\Component\Config\Definition\Exception\InvalidTypeException]
  Invalid type for path "fos_rest.format_listener.rules.fallback_format". Expected array, but got string

When I changed this to an array like so:

fallback_format: 
    - json

It says

[Symfony\Component\Config\Definition\Exception\InvalidConfigurationException]
  Unrecognized options "0" under "fos_rest.format_listener.rules.fallback_format"

I've also tried putting quotes around 'json' but it still says the same thing. A similar error happens when I try setting adding this line to the format_listener rules:

default_priorities: ['json', 'html', 'txt', */*]

But instead, it says Unrecognized options "0, 1, 2, 3" under "fos_rest.format_listener.rules.default_priorities" since there are four values being specified instead of just one.

It seems this bundle is insisting it's supposed to get an array, but then when it's given one, it can't read it.

Has anyone encountered this problem/is this a bug/is there a fix for this?

Was it helpful?

Solution

It looks like you are trying to set json as your default format for requests. If that is the case, it is done a bit differently now.

fos_rest:
    format_listener: true
    routing_loader:
        default_format: json

EDIT:

If you are wanting to force specific formats, then do something like this:

format_listener:
    rules:
        - { path: ^/rest/path, priorities: [html, json, xml], fallback_format: json, prefer_extension: true}

Here's a useful config that I found that is using the FOSRestBundle. It has similar examples to what I mentioned. Example Config

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top