GET Handled, thin Controllers and fun with Services

In an effort to keep our controllers thin, and to maintain our sanity as our projects grow larger, it becomes increasingly more important to shift logic out of our Symfony Controller and into a designated Handler class.

The idea behind our Handler class is that we want to abstract the whys and wherefores of where our data is actually coming from. Ultimately it's not the Controller's job to care about such things. So we pass the responsibility over to a specific Handler class which implements a common Handler interface.

At first this looks like you're creating way more code to handle (ahem, no pun intended) quite a simple task. And there is some truth to that. Really this methodology only starts to show its benefits as your projects grow - which they always seem to do in the real world, if the project is making money for the business.

This is really laying the foundations for the rest of our project. All our end points will use and re-use the various Handlers that we create, and in doing so, we can keep our code DRY and ensure shared logic only ever exists in one place.

By the end of this video you will have gained a good understanding of how to structure a real world RESTful API project in Symfony 2 using the FOS REST Bundle.

Code For This Course

Get the code for this course.