FriendsOfSymfony / FOSRestBundle

This Bundle provides various tools to rapidly develop RESTful API's with Symfony
http://symfony.com/doc/master/bundles/FOSRestBundle/index.html
MIT License
2.79k stars 703 forks source link

Using plural name in route with single name in the action #752

Closed AyhamAlzoubi closed 4 years ago

AyhamAlzoubi commented 10 years ago

Hey I am using FostRestBundle with Symfony2

I want to use the route /users/{id} with methods PUT, POST, DELETE

I have the actions:

deleteUsersAction($id)
postUsersAction($request)
putUserAction($id)

can't we have it as: deleteUserAction($id) with the same route /users/{id} because it makes sense to have one user has this $id

this works only for PUT but not for POST and DELETE ?

lsmith77 commented 10 years ago

i think the relevant code is somewhere around here: https://github.com/FriendsOfSymfony/FOSRestBundle/blob/master/Routing/Loader/Reader/RestActionReader.php#L410

though i guess such changes may then require a BC flag to prevent code from breaking

AyhamAlzoubi commented 10 years ago

Here I am pluralizing the route in any case and seems fine Can you have a look please?

https://github.com/FriendsOfSymfony/FOSRestBundle/blob/master/Routing/Loader/Reader/RestActionReader.php#L410

// if we have argument for current resource, then it's object.
            // otherwise - it's collection
            if (isset($arguments[$i])) {
                if (null !== $resource) {
                    $urlParts[] =
                        strtolower($this->inflector->pluralize($resource))
                        .'/{'.$arguments[$i]->getName().'}';
                } else {
                    $urlParts[] = '{'.$arguments[$i]->getName().'}';
                }
            } elseif (null !== $resource) {
                $urlParts[] = $this->inflector->pluralize(strtolower($resource));
            }
odino commented 10 years ago

To integrate:

This way we can provide consistency to the routing and to the action naming, even though Im not sure if there is any unhandled special case @AyhamAlzoubi is forgetting about...

AyhamAlzoubi commented 10 years ago

failing cases:

lsmith77 commented 10 years ago

i suggest you open a PR with any changes ..

lsmith77 commented 10 years ago

ping

Tobion commented 4 years ago

Closing as automatic route generation is deprecated: #1954