3

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()
    {

    }
}
Josep Alsina
  • 2,762
  • 1
  • 16
  • 12
Meh Di
  • 93
  • 1
  • 10
  • 1
    I would assume, that in your routes.yaml the type might ultimately be `annotation` (it's completely unclear, since you haven't defined any routes yet) as suggested in https://symfony.com/doc/current/routing.html#creating-routes-as-annotations – Jakumi Aug 12 '20 at 05:26
  • Please share more details - there is no v4.99 of Symfony – Nico Haase Aug 12 '20 at 07:02
  • I edited my post and added the code of fos_rest.yaml. – Meh Di Aug 12 '20 at 22:58

3 Answers3

1

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

IndyDevGuy
  • 126
  • 5
1

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],

Badr MOUMOUD
  • 166
  • 2
  • 10
0

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

Eliot8
  • 1