This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import random | |
| import json | |
| import string | |
| # get the ngrok tunnel url | |
| def get_ngrok_url(): | |
| """Function to get ngrok url""" | |
| url = "http://localhost:4040/api/tunnels" | |
| res = requests.get(url) | |
| res_unicode = res.content.decode("utf-8") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from aiohttp import web | |
| from http import HTTPStatus | |
| import validators | |
| import requests | |
| def validate_url_format(longurl: str): | |
| """This function returns True if the longurl is in a valid format""" | |
| return validators.url(longurl) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| """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 |
NewerOlder