Tuesday, March 11, 2008

map methods execute*() methods in Agavi

Agavi is architecturally beautiful. I can really appreciate the way they designed this thing. One fundamental problem with this framework, however, is that it lacks good documentation. You need to read the code, or ask others who already did, for you to answer some very simple questions.

In my case, I was looking for a way to change the HTTP verb mappings with AgaviWebRequest methods.

Agavi maps executeCreate() with HTTP PUT and executeWrite() with HTTP POST. If I use these functions in the context of REST architecture, it makes more sense if they are mapped the other way around. Although I understand that there is no single way to implement REST, there seems to be a general agreement that update operations should be mapped to HTTP PUT while create operations should be mapped to HTTP POST.

Fortunately, Agavi provides a simple (undocumented) way to change the mappings. In config/factories.xml, simply add:
              <request class="AgaviWebRequest">
<parameter name="method_names">
<parameter name="POST">create<parameter>
<parameter name="GET">read<parameter>
<parameter name="PUT">write<parameter>
<parameter name="DELETE">delete<parameter>
<parameter>
<request>
Thanks to the crazy guy, MikeSeth. =)

No comments: