Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FOSRestBundle - Allow only json + xml and default to json if no other requested

Could someone show me a reference configuration of FOSRestBundle that will only allow json + xml and willd default to json if "Accepted" or "Content-Type" has not been set.

My goal is to drop the templates html support and all other unnecessary formats (in my case).

Thanks in advance!

like image 907
n00b Avatar asked Jan 05 '14 02:01

n00b


1 Answers

Got it.

# app/config/config.yml
# ...
fos_rest:
    routing_loader:
        default_format: json
        include_format: true
    param_fetcher_listener: force
    body_listener: true
    allowed_methods_listener: true
    view:
        view_response_listener: 'force'
        formats:
            json: true
            xml: true
    format_listener:
        rules:
            - { path: '^/api', priorities: ['json', 'xml'], fallback_format: json, prefer_extension: true }

sensio_framework_extra:
    view:    { annotations: false }
    router:  { annotations: true }
# ...
like image 88
n00b Avatar answered Sep 18 '22 15:09

n00b