Skip to content

Instantly share code, notes, and snippets.

@jaydeepkarale
Last active June 23, 2022 12:54
Show Gist options
  • Save jaydeepkarale/48f0c8812e416970eb00335b5c1d85c0 to your computer and use it in GitHub Desktop.
Save jaydeepkarale/48f0c8812e416970eb00335b5c1d85c0 to your computer and use it in GitHub Desktop.
AIOHTTP Server In Python
"""Main file for performing url shortening"""
from aiohttp import web
# instead of adding routes one by one we use the RouteTtableDef which will auto collect all @route annotations
routes = web.RouteTableDef()
# this will create a route 127.0.0.1:8000/shorten
@routes.get("/shorten")
async def shorten(request):
"""Function to accept HTTP request with long url & call shortening logic
:param request: HTTP request
"""
return web.Response(text="Hello, World !!!")
if __name__ == "__main__":
# initialize a webapp named app
app = web.Application()
# add routes for the app, in our case we only have /shorten
app.add_routes(routes)
# run the web app
web.run_app(app, host="127.0.0.1", port=8000)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment