views:

125

answers:

2

I'm developing a Zend Framework based application and I found myself writing a skeleton for the API module. I read a bit on the web and I started writing the skeleton based on Zend_Rest_Controller. Turned out ok, key login required to use the API.

The questions started when a colleague of mine started implementing the skeleton in a proper API for one of our applications. He told me he thinks it would be better if we only had an usual Zend_Controller_Action extended in an API controller and in indexAction a Zend_Rest_Server that handles the object.

I'm a bit confused about this. From my personal point of view I'd want to have a "larger-than-average" controller containing each of the 4 actions (get, post, put, delete) and a bit of logic in each action rather than one action ruled by Zend_Rest_Server.

My problem is that I can't figure which of the 2 solutions is better from an architecture point of view; and of course, the most easily maintainable over time.

+4  A: 

Zend_Rest_Server is generally considered deprecated in favor of Zend_Rest_Controller/Zend_Rest_route. See this post by MWO'P, for instance.

This alone would push me firmly in the direction of Zend_Rest_Controller/Zend_Rest_Route.

timdev
I see. This is getting interesting... The minor problem with `Zend_Rest_Controller` is that you'll find yourself having a rather fat controller, the second solution being creating a service object for the object meant to expose via API. And that would translate in rest_controller->object_service->object->object_model->eventual_object_custom_abstraction which I think is fairly hard to maintain in a team without studying beforehand how you get the final object representation in the rest controller
Bogdan Constantinescu
The details of your implementation are really dependent on your domain, but it sounds like you're on the right track, generally speaking. I'm not sure exactly what is in each of your layers, but when I do this kind of thing, my controllers rely on a service layer that manipulates domain objects, and handles store/fetching via a persistence layer of some sort.
timdev
+1  A: 

If you want to do REST on Zend I suggest you take a look at the Resauce Framework

Darrel Miller