question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Custom operation route "Not Found" error

See original GitHub issue

My API Resource:

namespace AppBundle\Entity;

use ApiPlatform\Core\Annotation\ApiResource;

/**
 * @ApiResource(
 *     collectionOperations={
 *        "list"={"route_name"="campaign_list"}
 *     }
 * )
 * @ORM\Entity
 */
class Campaign {
...
}

My custom action:

namespace AppBundle\Action;

use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\HttpFoundation\JsonResponse;
use AppBundle\Entity\Campaign;
class CampaignList
{
    /**
     * @Route(
     *     name="campaign_list",
     *     path="/list",
     *     defaults={
     *          "_api_resource_class"=Campaign::class,
     *          "_api_collection_operation_name"="list"
     *     },
     *
     * )
     * @Method("GET")
     */
    public function __invoke()
    {
       return new JsonResponse(['test'=>'test']);
    }
}

My routing:

api:
    resource: 'api'
    prefix: /api
    type:     'api_platform'

Then I try to send request, and got 404 error:

2017-03-14 12 30 37

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:14 (7 by maintainers)

github_iconTop GitHub Comments

6reactions
mychalvlcekcommented, May 13, 2017

@mitalcoi yes, the route isn’t matched correctly because of itemOperation regex (regex is too open - matches everything).

quick solution: move “app” routing configuration before “api_platform” routing cfg so your custom routes will be matched before the generated (from api_platform) ones

app:
    resource: '@AppBundle/Action/'
    type: 'annotation'

api:
    resource: 'api'
    prefix: /api
    type: 'api_platform'
1reaction
mitalcoicommented, Mar 15, 2017

I’ve just applied your PATCH to fresh instance of api-platform, and routes are rendered OK (only difference is that I used _api_collection_operation_name instead of _api_item_operation_name from your PATCH) until I try to send smth to this route:

2017-03-15 13 14 59
Read more comments on GitHub >

github_iconTop Results From Across the Web

Custom Routes not working - 404 not found
I'm trying to create a custom route. The must be in this format: http://localhost:8000/home-back-to-school but instead I get a 404 not found ......
Read more >
Magenot 2.4 custom routes does not working. All time i get ...
When I put this mageplaza module in my app/code directory all works fine. I see one difference between the Magepaza module router and...
Read more >
Routing to controller actions in ASP.NET Core
Learn how ASP.NET Core MVC uses Routing Middleware to match URLs of incoming requests and map them to actions.
Read more >
Router tutorial: tour of heroes
Any other URL causes the router to throw an error and crash the app. ... A wildcard route can navigate to a custom...
Read more >
My Custom Route isn't working
I have started something, not entirely sure it's a plugin yet. ... The error says “{“code”:”rest_no_route”,”message”:”No route was found matching the URL ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found