In this chapter, we cover the details of CherryPy and TurboGears controllers. As you have already seen, CherryPy converts URLs into calls to controller objects. In Chapter 8, "RSS, Cookies, and Dynamic Views in WhatWhat Status," you saw a foreshadowing of how CherryPy handles HTTP requests and responses, when we looked at cherrypy.request.simple_cookie. In this chapter, we take a deeper look into the details of how a user request is handled. After we cover the basics of CherryPy, we turn to the TurboGears controller decorators. The @expose and @validate decorators make it easy to be flexible in the output that your controller gives. You can send out straight HTML, call a template to be rendered, create JSON to return to an Ajax call, or set up an XML interface to expose a web service. Finally, we delve into REST and provide you with a simple recipe you can use with TurboGears to create RESTful interfaces for your model objects. |