Search code examples
phprestsymfonyfosrestbundle

FOSRestBundle Catching All Routes


I'm trying to integrate FOSRestBundle into my application.

I want to use it only when a route matches like ^/api.

I really don't know how to use this bundle, and i think the documentation is pretty bad. (No offense).

fos_rest:
    format_listener:
        enabled: true
        rules:
            - { path: '^/api', priorities: ['json', 'xml'], fallback_format: 'html' }

When i request any route from my browser, i get this error:

No matching accepted Response format could be determined

I just want to match the routes starting with ^/api.

Any ideas?


Solution

  • You need to use zones feature:

    # app/config/config.yml
    fos_rest:
        zone:
            - { path: ^/api/* }
    

    read more about it in official docs: http://symfony.com/doc/master/bundles/FOSRestBundle/3-listener-support.html#zone-listener