简体   繁体   中英

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM