mirror of
https://github.com/sprockets/sprockets.mixins.http.git
synced 2024-11-15 03:00:29 +00:00
Example updates
This commit is contained in:
parent
f7992049c3
commit
ac57fff326
1 changed files with 15 additions and 17 deletions
32
README.rst
32
README.rst
|
@ -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
|
||||||
-------
|
-------
|
||||||
|
|
Loading…
Reference in a new issue