How to specify default format for FOS\RestBundle to json?

后端 未结 3 850
故里飘歌
故里飘歌 2021-01-11 14:20

My corresponding configuration is

fos_rest:
    view:
        view_response_listener: force

sensio_framework_extra:
    view:
        annotations: false
         


        
3条回答
  •  走了就别回头了
    2021-01-11 15:14

    You may specify a default_format that the routing loader will use for the _format parameter if none is specified.

    # app/config/config.yml
    fos_rest:
        routing_loader:
            default_format: json
    

    By default, routes are generated with {_format} string. If you want to get clean urls (/jobs instead /jobs.{_format}) then all you have to do is add some configuration:

    # app/config/config.yml
    fos_rest:
        routing_loader:
            include_format:       false
    

    Have a look at the FOSRestBundle documentation for more informations.

提交回复
热议问题