ramblings on PHP, SQL, the web, politics, ultimate frisbee and what else is on in my life

Me and Symfony2 learning about REST

I hate the frontend. Maybe its just all the scars from the IE4 and IE6 days I had to suffer through, but since then I have taken every opportunity to move myself further away from the frontend. Database-land seemed equally ridden with incompatibilities but for some reason I coped better with that. Anyway, somehow this entire REST thing seemed frontend to me. I think at some point I ended up with the misconception that REST is about URLs. Mea culpa. Thanks to Fabien and his advocacy around learning the HTTP protocol and ESI, I took a second look and realized that there is a lot more to it and that one should care regardless of one considers oneself a frontend or backend guy. Independently I did develop an interest in being able to easily return content in different formats, which let to the creation of the ViewBundle and the MultiplexBundle. but now I am actually trying to learn what REST is all about. And while I am at it, I am teaching Symfony2 as well, et voilà RestBundle!

First up I should say that RestBundle is actually a merge of the ViewBundle and EverzetRestfulControllersBundle developed by Konstantin and Bulat. The goal is to provide a tool chain to quickly develop applications that follow REST principles. I am still far away from being able to lecture on these, but I have tried to put together a list of my recent reading material on the topic. The Bundle provides several optional features. One is the ability to generate routing rules by following naming conventions for Controller actions. Another feature is the ability to parse request headers to determine the proper output format as well as decoding parameters out of the request body. The listener I implemented for this is actually also now integrated in the Silex micro framework. Finally it provides means to handle generation of the final output in a separate view layer. One key result of this separate view layer is the ability to decide how to handle the common use case of having to redirect after a form submission, but not necessarily after creating a new resource via JSON/XML.

I am trying to keep Liip's HelloBundle up to date with examples of how to use all of this. For now there is an example of a controller showing off the route generation and view layer. Another example illustrates how to handle redirection with the view layer, though I still have some todo's here. Finally there is a controller showing off the integration with the FrameworkExtraBundle from Sensio.

The next big steps I want to see happen is adding a normalizer for form instances. The idea being that via a normalizer it will be possible to extract the errors from a form instance and serialize these to JSON or XML to return a response to a resource creation or update from the same Controller that generates an HTML form otherwise. The other important thing I want to deal with soon is teaching the Serializer component how to lazy load encoders and normalizers (*nudge* Jordi *nudge*). I think the service mapping features of the ContainerWrapperBundle could play a key role there once we get the issues caused by interface injection worked out.

In the mid term I want to see the testing improved as the bits of pieces that I mainly authored are severely lacking in this department. Also the documentation could be organized a lot better and expanded. This would be a prerequisite to be able to get this Bundle into the standard edition of Symfony2 which would mean it would be more realistic to make it a requirement for the AdminBundle which not only I would like to see. A bit more long term I want to look more into some of the other HTTP status codes that we might want to support as well as how to best deal with API versioning.


Re: Me and Symfony2 learning about REST

I'm following your efforts to make Symfony2 more RESTful for quite some time now and really appreciate all the hard work you and the others are doing.

I'm really ashamed to not have some spare time to give you a helping hand right now.

Anyway, keep up the hard and good work!

Re: Me and Symfony2 learning about REST

Ciao Lukas,

cool, another great news after the one that HTML5 working group will reconsider their decision about dropping support for PUT and DELETE:

Re: Me and Symfony2 learning about REST

This rocks. Great job. Parts of this RestBundle remind me of Zend Framework's Zend_Rest_Controller & Zend_Rest_Route. Anyways I'm happy to help out where I can.

Re: Me and Symfony2 learning about REST

Yeah, I saw these components in ZF, though this Bundle tries to build even more tools to help in REST applications.

As for helping, we still got lots of open feature, test and doc tickets

Before you can post a comment please solve the following captcha.

your name: