On 02/24/2012 05:44 PM, Chris Travers wrote:
When I've done this before I've set it up slightly differently:
1. Deserialize request into some standard data structure ($request object) with headers, hash of data passed/deserialized request body, path
2. Main controller parses URL and uses conventions to load controller for a specific request, creates an appropriate response object based on request
3. Main controller calls standard method (determined by HTTP method/specific parameters) on the controller object with $request and $response object
4. Specific controllers load up native DB objects, populate with incoming data, call methods appropriate to actions, and populates $response object
5. Main controller returns serialized $response object
I'd say the main difference is taking the standard centralized stuff one step further than you've outlined, doing the URL parsing and establishing conventions before handing off to individual web service controllers.
I've also found it useful to have separate request and response objects, though at the moment I don't recall why. And of course have a different class for each type of response and request -- XML, JSON, HTML, etc. -- that implement standard methods that the framework can call regardless of type.
Excellent. Is this going to be available in 1.4?