2

I'm currently learning the basics of the FosRestBundle in a basic Symfony 3 project and am looking at creating a hyphenated REST route.

An example of a simple route I currently have, where GET /coffees hits CoffeeController::getCoffeesAction() as expected;

coffees:
  type: rest
  resource: ApiBundle\Controller\CoffeeController

I'm now looking at creating another rest controller to represent a coffee pot, so URLs follow a format like GET /coffee-pots to hit CoffeePotsController::getCoffeePotsAction(). I've tried every key I can think of whilst referencing the docs ("coffee-pots", coffeePots, coffee_pots etc) and I only ever get a 404. The rest of the configuration is correct, since if I change the key and action to just pots it works fine.

I have successfully implemented routing annotations within the Controller (e.g. @Get("/coffee-pots", name="get_coffee_pots")) but I'd rather avoid that unless it's a particularly bad practice to do so.

Is this possible? Thanks!

Chris Brown
  • 4,445
  • 3
  • 28
  • 36

1 Answers1

0

Old question but I just ran into this. From the console, type the following to list all of your routes:

php app/console debug:router

It will likely be at /coffeepots.

Collin Krawll
  • 2,210
  • 17
  • 15
  • I know what my current URL is, the question was how to generate hyphenated URLs. For what it's worth I've built another API with Symfony and had a lot more joy with API Platform than the FOS bundle. – Chris Brown Feb 02 '19 at 23:49
  • When I came across this, I was also looking to do hyphenated URLs. I dug into the FOS bundle and it doesn't look like it is possible unless you set a custom route for each action. I bailed and went with unhyphenated. Unhyphenated is the [standard for fedora](https://fedoraproject.org/wiki/Cloud_APIs_REST_Style_Guide#URL_Style) for what it's worth. I'll have to check out API Platform, thanks! – Collin Krawll Feb 07 '19 at 06:55