Skip to content

Instantly share code, notes, and snippets.

@spencergibb
Last active August 29, 2015 14:24
Show Gist options
  • Save spencergibb/4f4b56c0e31c300531e9 to your computer and use it in GitHub Desktop.
Save spencergibb/4f4b56c0e31c300531e9 to your computer and use it in GitHub Desktop.
import httplib
from twisted.web import server, resource
from twisted.internet import reactor, endpoints
class Health(resource.Resource):
isLeaf = True
def render_GET(self, request):
request.setHeader("content-type", "application/json")
return '{"status":"UP"}\n'
class Fortune(resource.Resource):
isLeaf = True
def render_GET(self, request):
conn = httplib.HTTPConnection('localhost', 5678)
conn.request("GET", "/fortunes")
res = conn.getresponse()
fortune = res.read()
request.setHeader("content-type", "text/plain")
return fortune
root = resource.Resource()
root.putChild('health', Health())
root.putChild('', Fortune())
endpoints.serverFromString(reactor, "tcp:5680").listen(server.Site(root))
reactor.run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment