"show" routes only available in POST?
Dear all,
I am just starting to use this bundle but I'm seeing some issues, I appreciate gurus to help offer some assistance.
The routes generated are as follows:
create GET /writer/create.{_format} delete DELETE /writer/{id}.{_format} edit GET /writer/{id}/edit.{_format} index GET /writer/index.{_format} new GET /writer/new.{_format} show POST /writer/{id}/show.{_format} <========== Note this is a POST request! update POST /writer/{id}/update.{_format}
The "show" is a POST request, which is odd, shouldn't it be a GET request? What's wrong here? Thanks!
If I have to support GET (regardless of what FOSRestBundle recommends), how would I do that?
can you paste the method names of your controller?
It is a test environment I'm working on, and is generated completely via doctrine:generate:crud, so nothing special.
public function indexAction()
public function showAction($id)
public function newAction()
public function createAction()
public function editAction($id)
public function updateAction($id)
public function deleteAction($id)
Also other information:
63 [JMSSerializerBundle] 64 git=git://github.com/schmittjoh/JMSSerializerBundle.git 65 target=bundles/JMS/SerializerBundle 66 67 [FOSRest] 68 git=git://github.com/FriendsOfSymfony/FOSRest.git 69 target=fos/FOS/Rest 70 71 [FOSRestBundle] 72 git=git://github.com/FriendsOfSymfony/FOSRestBundle.git 73 target=bundles/FOS/RestBundle 74 version=origin/0.6
1 [symfony] 2 git=git://github.com/symfony/symfony.git 3 version=v2.0.6 4
you should prefix your action methods with the http method you want to use.
aka getShowAction()
Thanks, it generated a GET but the routes become different, please check:
public function indexAction()
public function getShowAction($id)
public function newAction()
public function createAction()
public function editAction($id)
public function updateAction($id)
public function deleteAction($id)
create GET /writer/create.{_format} delete DELETE /writer/{id}.{_format} edit GET /writer/{id}/edit.{_format} index GET /writer/index.{_format} new GET /writer/new.{_format} update POST /writer/{id}/update.{_format} get_show GET /writer/shows/{id}.{_format}
notice that the get_show is now GET /writer/shows/{id}.{_format} rather than /writer/{id}/show.{_format}
Is this expected or "recommended defaults"? Is it changeable? I have a doctrine model that I have already exposed but now want to work with FOSRestBundle, so I do not want to break the interface. Thanks.
yes .. its not common practice to include the names of "actions" for anything but new/edit/remove forms/confirmation pages (these 3 are actually not necessary in a "proper" REST API and are just added to this Bundle to make it easy to use the generation logic for developers creating HTML representation for end users).
check for an example: https://github.com/FriendsOfSymfony/FOSRestBundle/blob/master/Resources/doc/5-automatic-route-generation_single-restful-controller.md
Thanks Smith, but I don't quite follow. Should I need to change the routes to GET /writer/{id}/show.{_format}, how would I do that? Thanks.
you seem to currently be using a hardcoded prefix writer ..
it would be better if you would remove that prefix and instead replace your show method with getWriterAction() etc
Updated... it seems to have issues for methods that goes by names such as "getSalesOrderAction"... which splits up into something funny like this:
get_sales_order GET /writer/sales/{id}/order.{_format}
yes .. it assumes that separate words refer to sub resources.
Thanks Smith! You're great ~ I will rename it accordingly and post again if I have questions. I hope this helps the other guys on this thread.