Cannot load resource "". Make sure there is a loader supporting the "rest" type

Viewed 3643

I face this Error while creating a REST API using Symfony V4.99 and fosrestbundle.

When I Run php bin/console debug:router I get this:

Cannot load resource "App\Controller\ListController". Make sure there is a loader supporting the "rest" type.

Here is the code of Routes.yaml:

lists:
    type      : rest
    resource  : App\Controller\ListController
    prefix    : api

Here is the code of fos_rest.yaml :

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

    exception:
        enabled: true

    view:
        view_response_listener:  'force'
        formats:
            json: true 

Here is the code of ListController.php:

<?php

namespace App\Controller;

use Symfony\Component\Routing\Annotation\Route;
use FOS\RestBundle\Controller\AbstractFOSRestController;
use FOS\RestBundle\Controller\Annotations as Rest;

class ListController extends AbstractFOSRestController
{
    public function getListsAction()
    {

    }
}
3 Answers

in symfony 5.* versus FOSRestBundle there is a problem with routes , try:

  1. install this https://github.com/handcraftedinthealps/RestRoutingBundle

    #> composer require handcraftedinthealps/rest-routing-bundle

  2. then add to config/bundles.php this line :

    HandcraftedInTheAlps\RestRoutingBundle\RestRoutingBundle::class => ['all' => true],

There is a bug/error with the recent version of FosRestBundle (3.0.2) Use this cmd to install it : composer require friendsofsymfony/rest-bundle:2.5.0

For newest (>3.0) you must change the route type from rest to annotation. Information Here

Related