FOSRestBundle icon indicating copy to clipboard operation
FOSRestBundle copied to clipboard

"show" routes only available in POST?

Open log0 opened this issue 14 years ago • 11 comments

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!

log0 avatar Mar 13 '12 15:03 log0

If I have to support GET (regardless of what FOSRestBundle recommends), how would I do that?

log0 avatar Mar 13 '12 15:03 log0

can you paste the method names of your controller?

lsmith77 avatar Mar 13 '12 15:03 lsmith77

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

log0 avatar Mar 13 '12 16:03 log0

you should prefix your action methods with the http method you want to use.

aka getShowAction()

lsmith77 avatar Mar 13 '12 16:03 lsmith77

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.

log0 avatar Mar 13 '12 16:03 log0

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

lsmith77 avatar Mar 13 '12 16:03 lsmith77

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.

log0 avatar Mar 13 '12 16:03 log0

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

lsmith77 avatar Mar 13 '12 16:03 lsmith77

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}

log0 avatar Mar 13 '12 16:03 log0

yes .. it assumes that separate words refer to sub resources.

lsmith77 avatar Mar 13 '12 16:03 lsmith77

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.

log0 avatar Mar 13 '12 16:03 log0