QP makes setting the reponse status, content_type and body easy, and to actually send the response one just raises a RespondNow exception. Here is the Gizmo(QP) Publisher method [evoque'd directly from the gz.pub.publisher python source code] that responds with the JSON rendering for the python object supplied as input data.
def json_respond_now(self, data, status=200): ''' (data:any) -> None -- sets response body with json dump of a python object, and raises RespondNow ''' response = self.get_hit().get_response() response.set_status(status) response.set_content_type('application/json', 'utf-8') # text/json response.set_body(json.dumps(data)) self.respond_now()
See it in action:
publisher.json_respond_now(dict(a=1, b='two', c='see'))