Example updates

This commit is contained in:
Gavin M. Roy 2017-04-26 22:19:48 -04:00
parent f7992049c3
commit ac57fff326

View file

@ -28,30 +28,28 @@ Example
This examples demonstrates the most basic usage of ``sprockets.mixins.http`` This examples demonstrates the most basic usage of ``sprockets.mixins.http``
.. code:: bash
python my-example-app.py
.. code:: python .. code:: python
from tornado import gen, web from tornado import gen, ioloop, web
from sprockets.mixins import amqp from sprockets.mixins import http
def make_app(**settings):
return web.Application(
[
web.url(r'/', RequestHandler),
], **settings)
class RequestHandler(http.HTTPClientMixin, class RequestHandler(http.HTTPClientMixin, web.RequestHandler):
correlation.HandlerMixin,
web.RequestHandler):
@gen.coroutine @gen.coroutine
def get(self, *args, **kwargs): def get(self, *args, **kwargs):
response = yield self.http_fetch('https://www.google.com') response = yield self.http_fetch('https://api.github.com')
if not response.ok:
self.set_status(response.code)
self.write(response.body)
self.finish()
if __name__ == "__main__":
app = web.Application([web.url(r'/', RequestHandler)])
app.listen(8000)
ioloop.IOLoop.current().start()
License License
------- -------