Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Handling of %2F
import asyncio
from aiohttp.web import Application, Response
@asyncio.coroutine
def resource(request):
return Response(text=repr(request.match_info))
@asyncio.coroutine
def custom_aсtion(request):
return Response(text=repr(request.match_info))
@asyncio.coroutine
def init(loop):
app = Application(loop=loop)
app.router.add_route('GET', '/{collection}/{resource_id}', resource)
app.router.add_route('GET', '/{collection}/{resource_id}/', resource)
app.router.add_route('GET', '/{collection}/{resource_id}/{custom_action}',
custom_aсtion)
handler = app.make_handler()
srv = yield from loop.create_server(handler, '127.0.0.1', 8080)
print("Server started at http://127.0.0.1:8080")
return srv, handler
loop = asyncio.get_event_loop()
srv, handler = loop.run_until_complete(init(loop))
try:
loop.run_forever()
except KeyboardInterrupt:
loop.run_until_complete(handler.finish_connections())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.