symfonyroutesyamlfosrestbundle

FOSRestBundle 2.4 | How to load rest type route


I upgraded my FOSUserBundle to 2.4 from 2.1 while I was upgrading my project to Symfony 3.4 from 2.8.

With the same code that worked before, and this yml file:

# app/config/routing.yml
api_request_backend:
    type: rest
    prefix: /api
    resource: "@AppBundle/Resources/config/default.yml"

-

# AppBundle/Resources/config/default.yml
api:
    type: rest    # This resource will have RESTful routes
    prefix:
    resource: "@AppBundle\Controller\ApiController"
    name_prefix: api_
apiV2:
    type: rest    # This resource will have RESTful routes
    prefix: /v2
    resource: "@AppBundle\Controller\ApiV2Controller"
    name_prefix: api_v2_
api_user:
    type: rest    # This resource will have RESTful routes
    prefix:
    resource: "@AppBundle\Controller\ApiUserController"
    name_prefix: api_

I receive this error:

Exception thrown when handling an exception (Symfony\Component\Config\Exception\FileLoaderLoadException: The file "/var/www/project/src/AppBundle/Resources/config/default.yml" does not contain valid YAML in /var/www/project/src/AppBundle/Resources/config/default.yml (which is being imported from "/var/www/project/app/config/routing.yml"). Make sure there is a loader supporting the "rest" type.)

Where am I wrong? I also tried to downgrade FOSRestBundle to 2.3.1 (I read this here) but nothing changes.


Solution

  • The issue is the invalid YAML. The following works:

    # app/config/routing.yml
    api_request_backend:
        type: rest
        prefix: /api
        resource: '@AppBundle/Resources/config/default.yml' 
    

    and

    # AppBundle/Resources/config/default.yml
    api:
        type: rest    # This resource will have RESTful routes
        resource: '@AppBundle\Controller\ApiController'
        name_prefix: api_
    

    thanks to xabbuh for the fix