Last active
August 29, 2015 14:24
-
-
Save spencergibb/4f4b56c0e31c300531e9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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