update aiohttp example

This commit is contained in:
Raphael Deem 2017-01-21 11:26:03 -08:00
parent 28396c8620
commit 121e059b3d

View File

@ -1,12 +1,9 @@
from sanic import Sanic
from sanic.response import json
import uvloop
import asyncio
import aiohttp
#Create an event loop manually so that we can use it for both sanic & aiohttp
loop = uvloop.new_event_loop()
app = Sanic(__name__)
async def fetch(session, url):
@ -24,10 +21,9 @@ async def test(request):
"""
url = "https://api.github.com/repos/channelcat/sanic"
async with aiohttp.ClientSession(loop=loop) as session:
async with aiohttp.ClientSession() as session:
response = await fetch(session, url)
return json(response)
app.run(host="0.0.0.0", port=8000, loop=loop)
app.run(host="0.0.0.0", port=8000, workers=2)