Search code examples
symfonyscaffolding

Generate RESTful web service scaffolding in Symfony2?


I see that there is a very useful system for generating CRUD forms from your entities.

I'm working on a component of my app that will be a JSON service. Is there a similar facility for generating CRUD operations that, instead of exposing an HTML form, accepts and returns JSON? This would allow you to quickly prototype a JSON service that allows RESTful interaction with your entities.


Solution

  • Please see my answer to your other question on how to generate CRUD and simple scaffoling.

    Extend SensioGeneratorBundle ( comes with the standard edition ) to generate FOSRestBundle compliant Controllers and routing to achieve what you are looking for.

    The controller templates can be found in SensioGeneratorBundle/Resources/skeleton/controller.

    The route templates reside in SensioGeneratorBundle/Resources/skeleton/bundle and are called routing.xml / .yml / ...

    An example REST controller ( with automatic route generation ) can be found here: LiipHelloBundle/Controller/ArticleController.php.