FOSRestBundle doesn't work in Symfony 4.1

Add line to config/packages/framework.yaml

framework:
    templating: { engines: ['twig'] }

it will solve

An instance of Symfony\Bundle\FrameworkBundle\Templating\EngineInterface >must be injected in FOS\RestBundle\View\ViewHandler to render templates.


Do you send the Accept: application/json in your request?

If not, you do not necessarily need twig, but you need to remove html from the format configuration in the bundle config:

fos_rest:
    format_listener:
        rules:
            - { path: ^/, prefer_extension: true, fallback_format: json, priorities: [ json ] }

The default is to have html in the priorities, and that requires twig.


You must enable the SensioFrameworkExtraBundle view annotations

sensio_framework_extra:
    view:        { annotations: false }