Skip to content

Instantly share code, notes, and snippets.

@Lothiraldan
Created June 15, 2015 20:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Lothiraldan/2e4b36ac55946ff0ba3b to your computer and use it in GitHub Desktop.
Save Lothiraldan/2e4b36ac55946ff0ba3b to your computer and use it in GitHub Desktop.
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