Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fixed JSON Serializer circuits.web example. Fixed Issue #66
  • Loading branch information
prologic committed Mar 23, 2014
1 parent b16d894 commit 118accc
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions examples/web/jsonserializer.py
@@ -1,6 +1,6 @@
#!/usr/bin/env python

import json
from json import dumps

from circuits import handler, Component
from circuits.web import Server, Controller, Logger
Expand All @@ -10,20 +10,18 @@ class JSONSerializer(Component):

channel = "web"

@handler("request_filtered", priority=1.0)
def _on_request_success_or_filtered(self, event, evt, handler, retval):
request, response = evt.args[:2]

event[2] = json.dumps(retval.value)
@handler("response", priority=1.0) # 1 higher than the default response handler
def serialize_response_body(self, response):
response.headers["Content-Type"] = "application/json"
response.body = dumps(response.body)


class Root(Controller):

def index(self):
return {"message": "Hello World!"}

app = Server(("0.0.0.0", 8000))
app = Server(("0.0.0.0", 9000))
JSONSerializer().register(app)
Logger().register(app)
Root().register(app)
Expand Down

0 comments on commit 118accc

Please sign in to comment.