Skip to content

[Routing] Incorrect routing on custom REST API methods (with demo-repo) #50134

Closed
@sebastianstucke87

Description

@sebastianstucke87

Symfony version(s) affected

6.2

Description

I have 2 routes:

  • standard: /api/example/{id}
  • custom: /api/example/{id}:some-action

When I execute the standard-route, I get this correct response:

{
  "php-method": "standard",
  "ID": "abc123"
}

But when I execute the custom-route, I get this incorrect response:

{
  "php-method": "standard", // should be "custom"
  "ID": "abc123:some-action" // should be "abc123"
}

How to reproduce

Please see this demo-repo: https://github.com/sebastianstucke87/symfony-routing-bug-with-custom-methods

(It is a fresh symfony projection with the Controller, the rest-client .http-files a detailed README.md 👍)

In summary, this is the Controller:

final class ExampleController
{
    #[Route(path: '/api/example/{id}', methods: ['GET', 'POST', 'PUT', 'PATCH', 'DELETE'])]
    public function standard(string $id): Response
    {
        return new JsonResponse(
            [
                'php-method' => __METHOD__,
                'ID' => $id,
            ]
        );
    }

    #[Route(path: '/api/example/{id}:some-action', methods: ['GET', 'POST'])]
    public function custom(string $id): Response
    {
        return new JsonResponse(
            [
                'php-method' => __METHOD__,
                'ID' => $id,
            ]
        );
    }
}

Possible Solution

No response

Additional Context

REST API Custom Methods:

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions