// MySomethingController.php
// look no s
public function getSomethingAction($args)
{
...
}
// routing.yml
my_something:
type: rest
resource: Blah\Bundle\BlahBundle\Controller\MySomethingController
running:
php app/console router:debug
Output:
[router] Current routes
Name Method Pattern
get_something GET /somethings/{args}.{_format}
Why is the route 'somethings' ( plural with an 's' ) instead of 'something'?
is this a setting I have somewhere? or is this expected?
after digging in the code:
Here it is:
private function generateUrlParts(array $resources, array $arguments)
{
$urlParts = array();
foreach ($resources as $i => $resource) {
// if we already added all parent routes paths to URL & we have
// prefix - add it
if (!empty($this->routePrefix) && $i === count($this->parents)) {
$urlParts[] = $this->routePrefix;
}
// if we have argument for current resource, then it's object.
// otherwise - it's collection
if (isset($arguments[$i])) {
if (null !== $resource) {
$urlParts[] =
strtolower(Pluralization::pluralize($resource))
.'/{'.$arguments[$i]->getName().'}';
} else {
$urlParts[] = '{'.$arguments[$i]->getName().'}';
}
} elseif (null !== $resource) {
$urlParts[] = strtolower($resource);
}
}
return $urlParts;
}
I've opened an issue:
in hopes that this would become optional
This is an update answer based on the ticket opened by @phillpafford.
Ismith77 commented on the ticket and I thought explained very well why:
Without the pluralization we wouldn't know the relationship between the methods which is going to be important for example when implementing #52. furthermore its a key idea of REST that we have the GET for a single element in a collection be in a "subdir" of the collection itself.
So if you do "proper" REST then /member/{id}.{_format} would be oddly named but it would be actually wrong if your collection itself wouldn't then also reside under /member{.format}.
The gist of all of this is .. the solution as is isn't so much about convenience than it is about enforcing people actually following REST principles.
PS: However I would like to point out that when you have a word like "data" which is plural on it's own this is a bit annoying...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With